QtQuick and Drag-n-Drop

Implementing drag-n-drop (from now on DnD) in QtQuick is like traveling to an up-side-down world. Instead of dragging something and dropping it on a zone, the dragged item (or, rather, the MouseArea controlling the drag) is responsible for keeping track of where it is.

I’ve experimented with a few tricks to resolve this, and I believe that I’ve sorted the dragging half. The question is if I want to improve the receiving end. The concept is that you have a DragArea – which is just a fancy MouseArea. It has a property, zones, which is a list of QtObjects implementing methods to test if the zone is being hovered and to drop the item on the zone. This makes it possible for me to re-align the world with my brain, where the zones accepting the drops are playing an active role in the DnD.

Still, I have to think a bit about how to simplify the zones. Preferably, I’d like to be able to have a DropZone item that does all the fancy things and just lets the end-user (erhm, QtQuick developer, that is), indicate if the item can be dropped and then handle the onItemDropped event. Will see if I have time to polish this over Christmas.

By the way, the new Qt docs really confuse me. Could someone please reduce all the fancy effects, like having to expand each method to see the details. Also, having the Detailed Description on the top kind of reduces the need for a brief. It also slows down my average use-case, i.e. go to the page of a class, pick a method, click it and read. If I want details, I could go to the page of a class, click more and read. To get to the methods in the new layout, I have to scroll for a while, how much depends on the class, then click the item. Also, sending links to the details of specific methods is no longer readable.

QtQuick and Models

Well, the title says it all, lets get started :-)

Proxy Models

Something that I would love to see in QML is the QSortFilterProxyModel. I guess it needs a wrapper of some sort, but being able to sort and filter – either based on a role and a regular expression, or based on a JavaScript function would make QML even more powerful.

Why is this an important feature? To me, the goal of using QML is to put all user-interface specific code in the QML-half of the equation. Adding capabilities to do sorting, and some filtering, to QML reduces the size of the C++ run-time and further decouples the data from how the data is shown.

Lazy Models

A long time ago (pre 4.7.4) I ran into the issue that when resetting a lazy model (i.e. a model implementing canFetchMore / fetchMore) does not trigger QML to poke at canFetchMore. Very annoying, but sorted in later versions of Qt.

Namespace Clashes

In my experience, QML needs the “::” operator. Binding text to the text from a model using “text: text” does not work. Being able to say “text: ::text“, or “text: data.text” would be nice. Even though the last approach prevents the usage of components with properties named data.

I guess there already might be a way to achieve this, but I’ve not found it. If so, please tell me!

qBound on Arm

When using qBound in combination with qreal, it is important to properly cast the upper and lower bounds, e.g.:

qreal x = qBound(qreal(0.2), v, qreal(1.5));

If you forget this, i.e by using the following code:

qreal x = qBound(0.2, v, 1.5);

Your code will happily work on x86, and some other platforms, but not on Arm. This is because qreal is a double on all other platforms than Arm. On Arm, it is a float. This leads to GCC complaining about not being able to instantiate the template.

Intel Graphics – 3D Artifacts

So I’m running a 13″ MacBook Pro with Ubuntu. It has the 2.7GHz Dual-core Intel Core i7 processor with integrated graphics. I’m running the i915 driver (which is what Ubuntu set me up with). Now, everything seems ok, until I run something 3D with (I think) transparent surfaces.

I can spot the issue in SuperTuxKart, but in Minecraft, I don’t have to look for it. It looks awful. I’ve included two screenshots – one from daytime and one from night. Notice that the noise in the image actually is noise, i.e. it changes all the time.

Also, when running the Minecraft game, the rest of the desktop gets messed up too (font rendering, etc) but as soon as I turn it off, everything is working again. Very annoying.

Anyone out there, perhaps you, who know how to solve this? I’d be really thankful!

MacBook Pro, Ubuntu and the Cinema Display

I’ve got a new laptop – a MacBook Pro. The 13″ model with the i7 CPU and no discrete graphics card from ATI or nvidia. Instead one relies on the graphics card built-in to SandyBridge.

This caused some issues with the Cinema Display that I’ve grown so fond of – and it looked as if a driver hack was needed. But, thanks to my helpful colleague Erik Botö, the magic modeline was found. The trick is to lower the refresh frequency. So, for everyone out there, this does the trick:

xrandr --newmode "1920x1200_45.00" 140.92 1920 2032 2232 2544 1200 1201 1204 1231 -HSync +Vsync
xrandr --addmode DP1 "1920x1200_45.00"
xrandr --output DP1 --mode "1920x1200_45.00"

If you want to, you can skip the last xrandr call and simply use the KDE Display Settings tool. The line above gives you a clone setup, which I prefer at work.

Metamorphosis

When I first got to know Qt, it was a cross platform tool. That was really the reason for me to start using Qt. It was a great cross platform tool. At the time, I was using a Tru64 based system with real X-terminals. You know, the ones where the screen really is a stupid terminal connected to the network. Tru64 meant a real Unix, as in non-Linux, setup alongside Alpha CPUs. Great for what the school wanted us to do, i.e. use Matlab and latex.

In this setting, I wanted to program something with a user interface. My experiences from the time was GEM, from the good old Atari ST range, VisualBasic, I’ve used 1.0, 2.0, 3.0, 4.0 and 6.0 – without liking a single version, and some plain win32 from C. I did try MFC a couple of times, but I never grew fond of it. So, the first thing that I tried was xlib, which isn’t fun to use. So, along came Qt (and KDE). I believe that it was Qt 1.42 or something like that. One forgets as years passes by.

Qt configured and built beautifully, and the cannon tutorial had me hooked. Standard widgets, custom widgets, user driven, timer driven… this toolkit could do anything. And it was easy to use.

Years pass and the chronology gets mixed up. I met some fellow Qt users at QtForum. I made my way from a common user to moderator. Then, in a series of sad events, the site was sold and the old owner simply vanished from the Internet. The reaction was to start QtCentre together with the rest of the moderators and build a proper community. I cannot thank Witold enough for all the energy he still puts into this site. He really should get more credit for his work. There are other people there too who work hard, but Witold has been there from day one.

Qt progressed, the X11 version was GPLed. So was the OS X version. So was the win32 version. Qt 4 brought many goodies: modularization, webkit, graphicsview, model-based viewing widgets, etc. The toolkit embraced all platforms and is really a great tool for cross platform desktop development.

My self, I wrote the Independent Qt Tutorial for Qt 3, then the Foundations of Qt Development for Qt 4. I started working with Qt as my day time job. I started speaking about Qt at conferences and user group meetings. What I spoke of was the ultimate cross platform toolkit. My favorite example was that Qt tries to integrate well with Gnome – it does not even pick sides in the KDE vs Gnome competition. The whole root of Qt is its cross platform abilities, and there Qt excels.

Then came changes. Trolltech grew. Nokia bought them. The big fish eat the small.

With the Nokia acquisition came a great energy. Qt was put in the limelight. This was the technology that Nokia would base its future on. Developers were attracted to Qt. Qt DevDays had to move to a larger venue to fit them all in, and it still was crowded.

There where some big company things going on. Name changes – Trolltech, Qt Software, Qt Development Frameworks. Anything works. For me, personally, Trolltech had charm. Bug big companies sometimes act in strange ways. They don’t always agree with themselves and they might have contradicting policies and whatnot.

With Nokia came the push of Qt as a platform of its own. Qt on Harmattan/MeeGo and Qt on Symbian where all of a sudden the core focus of all Qt development. This is not surprising, given that this is where Nokia could apply Qt. The focus of Qt Developer Days changed. Out with the widgets, in with QtQuick and bling. The cross platform nature and roots of Qt where seemingly forgotten.

Do not get me wrong. QtQuick is a great piece of technology and something that I use daily in my job. It helps me be real productive and saves me from writing tons of code to drive rich user experiences.

Then came changes. The Qt strategy of Nokia was replaced with a WP7 strategy.

Not only was WP7 the official way forward. The Qt-based N9 is not to be sold in large markets. Despite positive reviews it looks like it will be a sad tribute to what Qt and QtQuick can do. The question is, who will pick up the ball again? Will there ever be another MeeGo handset? Most likely not, as Intel just pulled out of MeeGo, or just renamed it Tizen. The focus seems to have shifted from QtQuick to HTML5. The big question at the time of writing is what will be the underlaying engine. I’m sure everyone agrees that it will be WebKit, but will it be hosted by Qt or something else?

But now Qt has started to find its roots again. Lighthouse made porting easy. Necessitas puts Qt on Android. Qt for iOS is an ongoing community port. Qt will once again excel as the cross platform solution of choice. The question here is if it is wise to merge the desktops into the QtQuick API. I’m not convinced yet. Being cross platform on desktop also means integrating with the desktops. Current desktops are widget based, and to be true, widgets rock on desktop things. When controlling a machine or writing a mail I don’t want bling, I want predictable, stable widgets that looks like they are supposed to.

Compare this to common device user interfaces. Here there is a difference between applications such as mail and todo apps. Here you want common components that integrate with the platform – much like widgets. These elements usually fit into the limitations of widgets as well. Square, non-overlapping, etc.

Then you have completely custom applications, think Angry Birds, where QtQuick is the ultimate tool. As QtQuick can encapsulate both these user interfaces, it is the ideal tool for this type of device user interfaces.

And the current hype – HTML5? I believe that QtWebkit is the best system for building hybrid web/native applications out there. And integrating QObjects with the JavaScript space much resembles integrating them into QML space.

After chaos; Metamorphosis

I look forward to a new spring for Qt. Having a common Qt core for all applications. QtQuick for device user interfaces and QtWidgets for desktop. The QObject model that we have learned to love and the power of C++ will be available to all. Still, the user interface can be integrated with the platform of choice or fully customized with QtQuick. Code less, create more, deploy everywhere.

Rendering Issues

I’ve run Kubuntu on an old MacBook Pro (revision 5.1) for over a year now, and it has worked great. However, last week, it became more or less unusable. It seems that some sort of blending operation results in noise.

When using the machine with some composition effects, it was completely unusable – moving a window resulted in a square or static noise. All edges of plasma widgets where covered in noise, etc. Disabling all effects meant that I can use the machine again, however, some noise prevails.

As you can see from the screenshot at the top of this post, it is visible in the panel. It is also visible in elements such as the slider and the upper right corner of the desktop folder plasma widget. Another factor is that the noise sometimes disappear when a repaint is forced, but it is “physical” enough to get caught in a screenshot.

So, dear lazy web, do you recognize this from somewhere? Is it the drivers? Is it something in kwinrc? Or is it hardware (perhaps graphics memory) failing?

Update. Thiago from Tro^H^H^HNokia Qt Development Frameworks^W^W^W^WIntel (apparently at a new job) told me to clear the image caches. Read the comment, follow the instructions, and everything works again!

Mythbuntu 11.04 and the Remote

I decided to do some server maintenance today, so I upgraded my Mythbuntu client to version 11.04. I upgraded the backend server as well, but that went smoothly, so I guess that isn’t of public interest.

The client is based on the Asus AT3ION-I Deluxe motherboard. Having upgraded the client, the boot time went from seconds to minutes, and the remote stopped working. After some dmegs, lsmod and Google action it turned out that this was due to the mceusb driver. It loads when the remote is detected, it then crashes, makes the hid-philips-asus.sh script lock the boot process for about three minutes and prevents the correct driver from being loaded. The fix, to blacklist mceusb, is described in the ArchLinux wiki.