Understanding how Qt draws a GUI component ?
-
Hi , every one
I heard that Qt now draws its GUI components fully natively , not like before (emulates them ) ,
what I want to know is :
The idea of how exactly Qt draw them natively in each platform ? is it just OS invoking (like someone in stackoverflow said) ?
please, help me to understand the basic idea .Thanks :-)
-
Qt is painting QtWidgets using QPainter, which uses (usually) the raster engine to draw the content. It is not using native OS calls, apart from few exceptions (file dialog, for example, which can be drawn either natively or using QtWidgets).
QtQuick is painted using scenegraph, so OpenGL. Also, no native OS calls here.
I think you either misunderstood (there are several meanings of the word "native" in computing) the stackoverflow post, or your information source is wrong.
-
I posted this question in stackoverflow before. but someone said
( I'm pretty sure it just makes OS calls. It's up to the OS or not whether it's actually hardware accelerated. Other parts of Qt use OpenGL directly. – Ben Jul 5 at 8:07 )
Now its clear :-)
Thanks a lot. -
OK, then to be clear: by "native" I've meant using native OS controlls, like wxWidgets library does: asking the OS to draw native scroll bar, or combo box, etc. Qt does not do this. It paints all the widgets itself, and only tries to mimick the looks of the OS it is running on.
But obviously, some kind of native OS calling is happening deep inside, in order to actually draw some pixels on the screen, and open native window container. But that is usually not important at all to high level UI developers.
Contrary to what Ben Jul said, you have a clear choice whether the widget should be drawn by the CPU or the GPU: widgets can use different painting methods (native, raster, OpenGL, for more see "here":http://qt-project.org/doc/qt-5/qpaintengine.html#Type-enum), and the user has choice which one should be utilised. Most people do not use that, though, because the default settings work well.
-
really interesting! thanks siederzio , is by default the cpu taking care of the draw?
-
For QtWidgets: yes.
For QtQuick: no, OpenGL is the default.
-
thanks a lot man, last question , if i am using widgets , and I am making a custom widged meaning overriding paint event.
If I want to switch to opengl do I have to be carefull about something or opengl/qt handles everything manually under the hood? -
Sorry, I am not experienced in this area enough to give you an answer.
-
no problem , what I can do is just try to switch the painer in a cusatom widget and see what happen , maybe doing a bit of banckmark aswell
-
Hi,
For mixing QPainter and OpenGL have a look at the Overpainting example