Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Qt draw its GUI Components ( Basic Idea )?

When I browsed the source code of Qt I didn't find how it actually draws a GUI component, but I know it uses OpenGL.

I want to know how does a GUI library like Qt draw its GUI components (ex : QPushButton ,QWidget)?

Can any one help me with a basic idea ?

like image 690
CodeMan Avatar asked Jul 05 '14 07:07

CodeMan


1 Answers

In Qt-project site :

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.

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.

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! [qt-project.org]), and the user has choice which one should be utilised. Most people do not use that, though, because the default settings work well.

Thanks.

like image 94
CodeMan Avatar answered Sep 28 '22 20:09

CodeMan