[PySide] Difference between QMainWindow QWidget and QDialog
Cristian.Maureira-Fredes at qt.io
Tue Mar 10 17:38:08 CET 2020
On 3/10/20 10:11 AM, JZA wrote:
> Sort of want to know the difference between the different widgets and
> when to use the one that is needed. Also if there is any difference
> codewise for creating and launching the class.
Everything in Qt comes from the QObject class ,
and all the Q* classes inhetit, at some level, from it.
So besides QtCore, there are other foundational modules
like QtGui, which provide all the classes related to the UI,
but not widgets, more like the action of drawing certain things
on the screen, from which an important one is called QPaintDevice .
Going one level up, you have the module QtWidgets, which has
as base the QWidget class,
which inherits from QObject and QPaintDevice, and it's the starting
point of all the other Widgets you already heard about, like
QMainWindow, and QDialog.
A QWidget can be filled manually by other QWidgets, like buttons,
labels, combo box, toolbars, status, bar, etc, to create a "real
application window", but since that's scenario is so common
there was a decision to create a really high-level widget
that contains many common "Sections" that one could configure,
that's QMainWindow .
As you can see on the "Detailed Description" diagram,
it already provides you with some areas you can interact with,
so if you want to build a standard window application that follows
that pattern, you can use it, otherwise you would need to build
one by yourself.
All widgets based on QWidget can be constructed and showed as:
w = QSomeWidget()
and that's the definition of Modeless widget,
since it's independent of other windows.
A QDialog, on the other hand, is a top level windows
which was design for short interactions with the user,
but it's not only Modeless, it can be modal too,
and for it to behave like a Modal widget, it needs to be executed
by the exec_() method, and not the show() one.
- QMainWindow: for using the same pre-made structure
- QWidget: for displaying something simple or building your own thing,
- QDialog: for short interactions Modal or Modeless
Dr. Cristian Maureira-Fredes
The Qt Company GmbH
Geschäftsführer: Mika Pälsi,
Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin,
Charlottenburg, HRB 144331 B
More information about the PySide