Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How do GTK and Qt integrate with Linux in comparison to how they integrate with Windows and OS X?

Ask Question

From my understanding, Qt and GTK on the Windows and OS X side are just wrappers around the native GUI libraries, like for OS X it wraps around Cocoa, and for Windows around Win32. However, my question is, how do they integrate with Linux? Do the Desktop Environment developers have to implement special libraries for either Qt or GTK or how does it work? I have looked around but I can't really find the answer.

Are you so sure that Windows and MacOSX have a native GUI? AFAIU, both can run on screenless server boxes Basile Starynkevitch Nov 24, 2015 at 8:21

A few further notes.

Neither GTK+ nor Qt use the native widgets of Windows and OS X. They approximate the look and feel using native APIs, but internally everything is all done custom.

GTK+ and Qt are responsible for, and define, the themes available to programs on Linux. Desktop environments typically provide a way to change the theme globally for all applications, but how this is done is defined by GTK+ and Qt. For example, GTK+ 3 typically uses ~/.config/gtk-3.0/settings.ini to store this information ( and there is a programmatic API to this file ).

Qt has a bridge for GTK+ 2 themes via QGtkStyle, and the KDE developers maintain versions of their Oxygen theme for GTK+ 2 and GTK+ 3. (The previous sentence may change in the future, especially now that GTK+ 2 is long dead.)

Update 1 : Unix systems only provide a way to reserve a rectangular region of the screen to do what you want with it, including drawing (as in plotting a bitmap image) to it. Drawing (as in drawing shapes) is done by hand. GTK+ uses a library called cairo to do its drawing; I believe Qt wrote their own (QPainter?). Both Windows and OS X provide drawing APIs (Windows has several; OS X has Core Graphics). (X11 does have drawing primitives, but I assume they are not expressive enough to be used for modern 2D graphics; I wouldn't know...)

The same applies to font rendering, though modern Unix systems tend to base their font rendering on some generally accepted base libraries (freetype, fontconfig, fribidi, harfbuzz). GTK+ uses Pango to do text layout (actually arranging blocks of text into lines and paragraphs) and drawing (Pango integrates with cairo); I believe Qt also uses its own (this time I'm not sure).

I wrote about what X11 does do some time ago.

Yes thats what I meant, its generates GUI's using it's own templates but uses the OS provided API on Windows and OS X TheRenegade Nov 24, 2015 at 16:46 Wrong update. X11 has native drawing primitives (even for drawing text ...) but they are not much used today. Basile Starynkevitch Nov 26, 2015 at 7:49

On Linux (desktops and laptops) the graphical screen is generally displayed (at least that was the case in beginning of 2015) by the X11 server. Your GUI app is communicating with that server thru sockets , often locally on a Unix socket like /tmp/.X11-unix/X0 . The X11 server is generally Xorg .

For some embedded devices like Android mobile phones or some gadgets (GPS in cars, automotive or medical device industry) it is different ( DirectFB , framebuffer devices -which is used by the X11 server on your desktop, ...)

Some distributions are switching to Wayland (or perhaps to Mir ). Since I don't know these much, I cannot explain the gory details. AFAIU, there is still some server involved (which, like Xorg, is the only user-land software component talking to your graphics card) and some protocol, and major toolkits like Qt & GTK are been adapted to them (so if you code for Qt or for GTK, you don't care about those details, but you should upgrade your toolkit).

The graphical toolkits (Qt, Gtk) are interacting with the X11 server (or the Wayland one) thru some specific protocol(s), e.g. X Window System protocols for X11. For historical reasons, these protocols are quite complex, and practically require to follow some conventions like EWMH .

See also this answer to a related question. I explain there that X11 is not used today as it was in the previous century; in particular the server-side drawing abilities of X11 (e.g. Xlib's XDrawLine or XDrawText ) are rarely used today, because the toolkit is drawing a pixmap image client side and sending it to the server.

Notice that you might consider giving not a GUI interface, but a Web interface, to your application (e.g. using libraries like libonion , Wt , ....); then your application becomes a specialized Web server, and the user would go thru his browser (in his desktop/laptop/tablet/phone) to interact with your app.

Practically speaking, user interfaces are so complex that you really should use some toolkit for them ( Qt if coding in C++). Coding from scratch (even above Xlib or XCB for X11) would requires years of work.

There exist several other widget toolkits above X11, e.g. FOX toolkit , FLTK (but most of them have much less features than Qt or GTK).

There's no clear answer. There's no native GUI on Linux, as there is on Windows and OSX. X11, which is windowing system used on Linux (this applies to Wayland and Mir too), is very basic and low level and is responsible mainly for handling input devices and allocating windows to applications. It does not provide any GUI components such as buttons or text fields. In that sense, both Qt and GTK+ can be seen as "native" Linux GUI libraries. To make matters worse, desktop environment plays a part too. On Gnome, GTK+ can be seen as more "native", whereas on KDE QT is more "native".

Are we so sure that e.g. OSX (and perhaps Windows, which I don't know) are having a native GUI? AFAIU, you could run them on a screenless server. Then I would not call the GUI a native one !! Basile Starynkevitch Nov 24, 2015 at 8:19 You could probably also strip networking, sound etc from OSX and Windows and still have somewhat functioning system. Does it mean beforementioned system do not have native network/sound APIs? Cocoa is integral part of OSX installation, so is WinAPI. This is what I meant by native API . el.pescado - нет войне Nov 24, 2015 at 8:31 Then the X11 server and some desktop software is integral part of most Linux desktop or laptop installation (but a headless Linux server won't have them) so in some sense Qt and/or GTK would be a native API on these Linux systems, hence your claim that "there is no native GUI on desktop Linux" could be questioned. But I am wordpicking, it does not matter much Basile Starynkevitch Nov 24, 2015 at 8:36 When we say "native", we mean that OS X and Windows have a OS-developer-sanctioned, officially-provided, and universally-used set of controls, dialogs, etc. On OS X this is called Cocoa; Windows doesn't have a name for this (we just call it the Windows API) but most of the work is shared between user32.dll, comctl32.dll, and comdlg32.dll (with some help from Explorer). Unix systems have no such thing; GTK+ and Qt are the closest, and both of them are entirely separate (including in implementation). andlabs Nov 24, 2015 at 14:25 Or to put it a different way, OS X and Windows provide the window management features of X11 and the widget toolkit features of GTK+/Qt as part of their native APIs; Unix traditionally separates the two. andlabs Nov 24, 2015 at 14:35

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .