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
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.
–
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.
–
–
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".
–
–
–
–
–
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
.