What’s the difference between QMainWindow, QWidget and QDialog
qt-creatorqt4qtwidgets
What's the difference between QMainWindow, QWidget and QDialog?
Best Answer
A QWidget is the base class for all drawable classes in Qt. Any QWidget-based class can be shown as a window by showing it when it has no parent.
A QDialog is based on QWidget, but designed to be shown as a window. It will always appear in a window, and has functions to make it work well with common buttons on dialogs (accept, reject, etc.).
QMainWindow is designed around common needs for a main window to have. It has predefined places for a menu bar, a status bar, a toolbar, and other widgets. It does not have any built-in allowances for buttons like QDialog does.
Having the same problem, I found the solution here.
QMainWindow sets its window type to Qt::Window so that it will be in an independent window even if it has a parent (you can confirm this by calling show() on your QMainWindow, and you will see it in its own window). Try adding the line
Best Answer
A
QWidget
is the base class for all drawable classes in Qt. AnyQWidget
-based class can be shown as a window by showing it when it has no parent.A
QDialog
is based onQWidget
, but designed to be shown as a window. It will always appear in a window, and has functions to make it work well with common buttons on dialogs (accept, reject, etc.).QMainWindow
is designed around common needs for a main window to have. It has predefined places for a menu bar, a status bar, a toolbar, and other widgets. It does not have any built-in allowances for buttons likeQDialog
does.