views:

1442

answers:

3

I've been using QT for a while now and I've been wondering about something regarding the way the GUI is painted in Windows.
Is it really painting all the buttons, edit boxes, combo-boxes, check-boxes, tabs etc' on its own using QPainter or is it somehow using the native widgets?

The fact that it can do custom styling and skinning suggests that it does in fact draw everything using QPainter but how can this kind of code possible be maintained? Did the QT developers really reverse-engineer the entire functionality of the windowing system? isn't that somewhat wasteful?
Another evidence to this is that if I'm using Spy++ on a QT gui then all the windows are showing with a class name equal to "QWidget". If it were using the native widgets shouldn't these be "BUTTON", "STATIC" etc'?

What about on other platforms? Is it doing the same in Max OSX as well?

+2  A: 

The QWindowsXPStyle documentation has this to say:

"Warning: This style is only available on the Windows XP platform because it makes use of Windows XP's style engine."

The Qt Wikipedia page has this to say:

"Use of native UI-rendering APIs

Qt used to emulate the native look of its intended platforms, which occasionally led to slight discrepancies where that emulation was imperfect. Recent versions of Qt use the native APIs of the different platforms to draw the Qt controls, and so do not suffer from such issues.[24] (See also wxWidgets, which uses native APIs for most widget functionality.)"

Mihai Limbășan
+5  A: 

On Windows XP and Vista (except when the display settings set to Classic), the widget painting via QWindowsXPStyle and QWindowsVistaStyle actually use the low-level theme-specific drawing (uxtheme.dll) so that e.g. a push button looks like a native one. On older version of Windows, Qt emulates the widget painting through QWindowsStyle.

The situation is similar on Mac OS X, where QMacStyle relies on the Appearance Manager to delegate the low-level painting of the widgets.

For X11, usually Qt uses its own style painting and has certain styles which emulate some window system, e.g. QMotifStyle has similar look-and-like to Motif without actually loads and depends on Motif environment. However when running under GNOME, optionally Qt can use native Gtk+ theme via QGtkStyle.

Ariya Hidayat
A: 

Qt indeed paints all widgets itself (whether using a platform theming API or "raw" GDI/X/etc doesn't really matter). If it used native widgets (like wxWindows does), it would be almost impossible to hook into the styling to change even the minutest of detail, let alone use an off-the-shelf widget to add custom functionality on top.