Here is a new addition to my series on common user interface mistakes in KDE applications.
This time I want to talk about being GNOME friendly. While that may sound odd for a KDE developer to think about GNOME, assuming we want our applications to reach the largest possible audience, we should try to ensure GNOME users get a pleasurable experience. After all, a user is a user, there are efforts going on to ensure KDE works well on Windows and Mac OS X, I think we should also take care of GNOME users. They are at least as likely if not more likely to contribute back to our applications.
As usual with Qt, it already does most of the work for us: when a Qt or KDE application is running on a GNOME desktop, it will uses the “gtk+” Qt widget style by default. This widget style uses GTK+ primitives to draw widgets, which helps a lot to blend your application in the GNOME land.
Testing
You can of course test how your application behaves on GNOME by running it on the GNOME desktop. This is interesting to do, at least to keep an eye on what our fellow competitors are doing, but it takes quite some time. There is a faster way: start your application with these arguments: “-style gtk+”.
KWrite running with the GTK+ style (Clearlooks GTK+ style):

“It doesn’t work!”
What happened? If you get a message like that one:
The style 'gtk+' was not found
Tough luck: your version of Qt was not built with gtk+ support, not much to do here, except rebuilding Qt or using a different one.
If on the other hand you get something which looks a lot like Oxygen, chances are you are running the Oxygen GTK+ theme! This theme is great to integrate GTK+ and GNOME applications on a KDE desktop, but it’s not really helpful here. There are a few ways to change your GTK+ theme from within KDE. The simplest one is probably “kcm-gtk”, a GTK+ KConfig Module available from https://code.launchpad.net/kcm-gtk (Would be a nice candidate for inclusion in KDE SC!)

Making your application GNOME friendly
Enough testing, let’s fix bugs now!
Double margins
First of all, be on the lookout for my all-time-favorite pet-peeve: “double margins”. Oxygen often reduces the impact of double margin problems, but other styles do not. Here is for example a screenshot of Partition Manager with Oxygen:

Now, the same application, using the GTK+ style:

As you can see, there is quite a lot of wasted space. The fix is simple: call setMargin(0) on the layout in the embedded widget and the problem will go away.
-
note 1: QLayout::setMargin(int) is deprecated, and one should be using QLayout::setContentsMargin(int, int, int, int), but I can’t
get used to it: setMargin(int) is much shorter. Please Qt people, “un-deprecate” setMargin(int)!
-
note 2: Sorry for the french on the screenshots, hopefully it does not prevent you from seeing what I mean
QFormLayout
Another good practice to make your application GNOME friendly is to use QFormLayout instead of QGridLayout for typical “label: [edit widget]” dialogs. Using QFormLayout ensures your labels will be correctly aligned: KDE 4 HIG says labels should be right aligned, while GNOME HIG prefers them to be aligned on the left.
Use standard dialog classes
One of the oldest GNOME vs KDE troll is button order in dialog boxes: KDE uses the OK-Cancel order, while GNOME uses Cancel-OK. If you use KDialog instead of QDialog as a base class for your dialogs, you won’t have to worry about it: the button order will change according to the platform.
If you cannot use KDialog, for example because you develop a Qt-only application, do not create individual OK and Cancel buttons: use QDialogButtonBox. This class lets you define a standard dialog button bar: you just need to specify which buttons you need. If for some reason you develop a KDE application but do not want to use KDialog, be sure to use KDialogButtonBox, KDE version of QDialogButtonBox.
Icons
This one is for Qt-only applications: instead of embedding your own copy of the generic open, close, save… icons, consider using those coming from QStyle::StandardPixmap. Your application will automatically use GNOME icons when running on GNOME and KDE icons when running on KDE.
Update: Pau Garcia i Quiles points out you can also use QIcon::fromTheme(). You won’t automatically get icons on Mac OS or Windows this way (contrary to using QStyle::StandardPixmap), but you get access to all icons from the current freedesktop.org icon theme, this is likely to cover most if not all of your icon needs.
Others
Sometimes you need to be ready to go the extra mile. For example, Gwenview start page used to be ugly and difficult to use with GTK+ themes because the tabs would not be rendered using the correct color. I worked around this bug by setting the style of the tab widgets to Plastique when running on GTK+.
Before:

After:

If you are interested, here is the diff implementing this hack.
Conclusion
That’s it for this episode, now lets see if can make our applications as beautiful on GNOME as they are on the KDE desktop!

Advertisement
Like this:
One blogger likes this post.
Nice article. Qt/KDE everywhere, on Gnome, too :-p
How about – for a change – let the GNOME side the one that is friendly to KDE/Qt?
KDE ports Oxygen to GTK. The GTK theme wrapper was also written by Qt/KDE. No stock GNOME theme was ever ported to KDE/Qt by its authors.
KDE uses the fdo icon naming specification for maximal compatibility. GNOME still doesn’t fully implement it.
No GTK application I ever saw, adjusted to the Plasma Workspaces button order.
GNOME so far refuses to implement the StatusNotifier protocol, even though it was submitted to fdo.
It’s not like any GNOME user would ever install a KDE application to run under GNOME – at best Qt-only applications.
I totally agree with Markus. When will GNOME ever make an attempt to do anything for us KDE users? It seems it’s always us KDE developers that do everything for them. They want us to implement their standards and make everything work great for them, but in the mean time, they won’t do it back. I guess that is the GNOME community for you. Hence why I never go back to their world. KDE has proven to me over time that they are pretty much imho the only ones who really care about the Desktop Environment.
Similar sentiments have been found in the recent GNOME/Canonical spat.
> How about – for a change – let the GNOME side the one that is friendly to KDE/Qt?
> KDE ports Oxygen to GTK. The GTK theme wrapper was also written by Qt/KDE. No stock GNOME theme was ever ported to KDE/Qt by its authors.
> KDE uses the fdo icon naming specification for maximal compatibility. GNOME still doesn’t fully implement it.
Things won’t change with such an attitude.
> No GTK application I ever saw, adjusted to the Plasma Workspaces button order.
Try GIMP.
> GNOME so far refuses to implement the StatusNotifier protocol, even though it was submitted to fdo.
This failure can at least partly be attributed to fdo lack of decent protocol agreement process. If you read the archives you will see GNOME developers were interested by the spec but they wanted some changes. The changes were refused and discussion ended.
> It’s not like any GNOME user would ever install a KDE application to run under GNOME – at best Qt-only applications.
That is grossly wrong. Ask digiKam devs if they don’t have any GNOME users. Ask the same question to Amarok devs. Heck, I even get feedback from GNOME users for Gwenview, and it’s not like there is no GNOME equivalent image viewers. Sure GNOME integrists won’t install anything coming from the other side, but I don’t care about them. I don’t care about KDE integrists either, I care about open-minded, free software users and developers.
Well written response, +1.
Things didn’t change with Qxygen-GTK, the QtGTK theme engine, automatic button ordering,…
Oh yes, you’re right. GIMP seems to do it. The only “GNOME” application that never cared about the GNOME Interface Guidelines is the only one not on a GUI crusade trying to force the GNOME HIGs on everybody else. Awesome…
I’ve read that no GNOME person ever bothered to read the specs until it was too late for drastic changes.
There is, at least today, no real interest to adopt the specs at least as better fall-back solution than the crappy XEmbed method.
They say it may come in the future if anybody is ever willing to implement it. Nobody is.
I’m open minded in a way that I always try out the latest GNOME software but I don’t think it makes sense anymore to waste resources to make KDE applications look OK in a hostile environment. Oxygen-GTK at least makes sense from a KDE POV because it makes GTK applications look good in KPW.
I understand the rationale behind your post: Unity 2D is written in Qt which means there is a likelihood that Ubuntu 11.10 will ship a few Qt applications and as a Canonical employee you don’t want them to look bad. That’s fine but realistically no real KDE application will be bundled with Ubuntu because the deps are too large.
For new applications using QFormLayout etc. is probably no increased workload but refactoring existing applications is, at least IMO, not worth the effort for a handful of users.
If GNOME is an “hostile environment”, I wonder what you would call Windows or Mac OS. Do you also suggest developers working on porting KDE on those platforms should stop?
This is my personal blog. The rationale behind my post is to share with other Qt and KDE developers the little amount of wisdom I think I gathered. Nothing written here has ever been suggested by Canonical or any other company I used to work for.
There I agree with you. This is why I hope the work on modularizing kdelibs will be a success.
Users of Mac OS X and Windows are largely indifferent about the used toolkit. Mac users don’t care as long as it integrates nicely while Windows users never cared at all about consistent GUIs.
GNOME users are the only user group I know that is (at least for a large part, I grant you that there is a small fraction that uses Amarok and digiKam) actively boycotting anything KDE-related.
I guess there is no way to change your mind. Feel free to continue spreading your hatred. I would appreciate however if you would do so on your own blog rather than here.
He doesn’t spread hatred, but he describes reality. Btw. GIMP doesn’t suck in KDE, because GIMP is not a gnome application.
Maybe hatred is too strong a word. Still, excluding users just because they use the GNOME desktop is at best discrimination.
Nobody is talking about excluding GNOME users, ie. checking whether GNOME runs and then refuse to execute the application. That would be mean.
I’m also not saying that for new applications it’ll make perfect sense to take care and follow your advises. After all, it’s no added work, right?
The only aspect that IMO does not make sense is to redo all existing applications because the workload is high (depending on the amount of KDE’isms used, of course) for little gain.
I’d rather see the developers fix actual bugs than to redo cosmetics for a tiny fraction of users.
Heck, even when I use GTK apps under KPW I’d rather see a crah bug fixed than to “fix” some benign button placement “bug”.
The KDE devs wanted a spec that gave the workspace complete control over the presentation of the StatusNotifier while the GNOME devs wanted a spec that gave complete control to the apps. The fundamental design goals were different so it’s not surprising that many of the changes proposed by the GNOME were rejected, nor that GNOME has refused to adopt a protocol that it believes to be fundamentally flawed. Fortunately, it seems everyone else besides GNOME agrees with KDE, and once that approach is proven, perhaps GNOME will fall in line.
That doesn’t make sense. What part eg. of the Juk tray icon is controlled by Plasma?
Not saying I agree with the idea that apps should be in control of status notifiers, but it is true the workspace has complete control over the presentation. Juk (or any other application) is merely asking for its icon to be displayed. The workspace is free to use it or to substitute it with another one. The Plasma applet will substitute icons with versions matching the current Plasma theme if there are available alternatives. And it is a good thing because it helps providing consistency.
@Markus, Keith
+1
Gnome makes everything to be INCOMPATIBLE with KDE. There’s any good will from their side. Thus, I don’t see a single reason to make applications compatible with gnome. I don’t care about gnome at all, it can die and I won’t notice.
Huhu there are you again. Trolling against Gnome this time? Was communism and the dirty muslims threating honest citizens within the EU and UN not enough? Gnome is free software after all and you won’t get any Gnome users if you can’t show them off nice KDE features/apps in the first place. Even though KDE has far less support than Gnome from commercial vendors that is why it is soooo nicely working and successful in the end. Not because KDE devs flame other fanboys without arguments… Have you ever used Gnome? It is pretty well done compared to Windows XP/Vista/7…
Man, you really have to think about your aggressions. You are the perfect subject for right wing/conspiracy manipulation. Not only you have problems with the world after all…
I gave evidences unlike you. I don’t have any problems with Muslims. I prefer Muslims than the Left. Looking how both DEs are evolving it seems KDE has superior support compared to gnome. Just check plasma and gnome shell and guess which one is disaster? Gnome isn’t successful at all. Canonical and Ubuntu are. I used gnome when KDE 4.0 arrived, but I switched immediately when 4.1 appeared. I used gnome few times later too. Read Aarons posts and comments, there are many evidences about gnome being unfriendly to outside world. Summing up, those are gnome folks who have problems with others. According to manipulation check the facts about novell, ximians and gnome foundation. Isn’t supporting ms makes novell and gnome foundation hypocrites?
Nice, I’m now using openbox as my primary desktop shell because I have an old laptop, but I still use mainly KDE apps. GTK/Qt/KDE integration matters for me.
Slightly off-topic: Gwenview on Windows XP has the same text color problems with the native Windows XP Qt style (using current stable KDE on Windows, which is still 4.5.4).
If you have a development setup, can you try modifying the code to see if hardcoding Plastique would fix the issue? A crude way to test is to open app/startpage.cpp, and add a “return true;” as the first line of the “styleIsGtkBased()” function.
As always, an interesting article!
For the icons, if you use Qt 4.6 or newer, you can use QIcon::fromTheme to show the icons that are the best fit for the current theme.
Very good suggestion Pau! I just added a paragraph about QIcon::fromTheme() to the Icons section.
When possible, I use QIcon::fromTheme in combination with QStyle::StandardPixmap for the fallback. For instance, for the DVD icon:
QIcon::fromTheme(“drive-optical”, qApp->style()->standardIcon(QStyle::SP_DriveDVDIcon));
Or with your own icon in case Qt does not provide a suitable fallback.
Guys,
I use both DE’s. However, I don’t see the point of this article. The two screenshots (under Double margins and Others) look really the same. I admit that I didn’t wear my glasses but if I had to wear them to notice a difference, then something is wrong.
Or is the point that this article wants to make, that KDE is much more straight forward to develop for in stead of Gnome?
No offence, but may I ask what gnome you have in mind? Old gnome with panels etc aka “GNOME legacy”, new GNOME Shell or maybe Unity? There is such a mess in gnome land now, that there is really hard to support something
I don’t have any particular GNOME desktop in mind. I believe the suggestions I make in this post should help blending KDE applications in any GNOME-based desktop, be it GNOME 2, GNOME Shell or Unity.
Thank you for looking this way
Please ignore the people commenting about GNOME not trying to integrate. As you have probably already figured out, none of them would have contributed a single line of code to either GNOME or KDE so this doesn’t actually affect them at all.
I don’t contribute to KDE? That’s news to me…
In fact before Aurélien made it his personal crusade to improve KDE GUIs, I felt like I was the only one who even cared.
If you eg. noticed any stupid placeholder questionmark icons turning into proper icons during the releases, thank me for that.
I’ve liked this series very much. Do keep writing. I hope you don’t get too drawn into some of the obvious flamebait in the comments.
Thanks! Don’t worry I don’t plan to stop.
Pingback: March 2011 wrap-up « Aurélien’s room