Things i've made

Looking for more? See a list of everything i've made.

Tuesday, September 13, 2011

Gtk to Qt Port - Work in Progress

Not to long ago I started on a project to port a large application from Gtk to Qt. So far the progress has exceeded my expectations and I have even been able to spend some time on achieving pixel perfect layout of widgets, something I had previously relegated to the later stages of the project.

I went about implementing a perfect GtkBox implementation in Qt. The implementation route I chose was  to subclass QLayout to create QGtkBoxLayout which acts as a standard Qt Layout where the layout has a homogeneous parameter, a spacing size, and a direction. Each child has fill, expand, and padding parameters - much like GtkBox.

GtkBox demo in Gtk

GtkBox demo in Qt on Linux
GtkBox demo in Qt on Windows

As you can see in the demonstration screenshots above, Qt has a minimum size imposed on buttons but otherwise, the layout is quite close to the arrangement produced by Gtk.

Box layouts aside, some of the more interesting, but significantly less visual implementation hurdles overcome so far comprise:

  • Correct signal emission, blocking, finding, and miscellaneous management
  • Emulating Gtk's object reference counting in Qt ensuring correct widget destruction
  • Working Idle and timeout callbacks on Linux, Windows, and OSX
  • Mapping between different conceptual designs for GtkMenu, GtkRadioButton, and importantly, the GtkTreeView family of objects
So far a lot of functionality is implemented and the application I am porting is working for a lot of workflows. The only aspect of Gtk that I have been unable to port without some source modification of the application code is the use of GtkScrolledWindow. Fortunatly, or unfortunately as you may view it, many Qt widgets natively support scrolling without the need for a scrolled window whereas many Gtk widgets rely on the functionality of the scrolled window to be useful. Changing the application code to not use scrolled windows on self-scrolling widgets has been the easiest out here. A prime example is the GtkTreeView where its Qt counterpart, QTreeView, scrolls by itself. Inserting a QTreeView into a scrolled window only results in two sets of scrollbars - quite undesirable.

The specific application I am porting has the annoying quality that it was previously a Motif application and uses an XmForm emulation class for Gtk. This did not port across so well so it ended up being implemented as a QLayout, much like the GtkBox. So now I also have a QXmFormLayout class that works quite well.

No comments:

Post a Comment