In my rather complex app, I create several QmainWindows, which show/hide depending on conditions. To make their behavior more deterministic, I want to set their position using setPosition()
. The problem is that QMainWindow is not derived from QWindow, as I assumed. So, it has no setPosition()
. My questions:
Why QMainWindow is not derived from QWindow? (Just my curiosity)
How can I set the position of a QMainWindow?
(@Tarod and @AlexanderVX already gave the answers in the comment, but here they are again)
Why QMainWindow is not derived from QWindow?
Mainly because QMainWindow
existed long before QWindow
was invented.
QMainWindow
inherits QWidget
. QWidget
is flexible; it can become a top-level window, or it can become part of a larger widget. This means you can put QMainWindow
inside another widget (but you probably don't want to do that).
How can I set the position of a QMainWindow?
The same way you set the position of any other QWidget
: http://doc.qt.io/qt-5/qwidget.html#pos-prop (QWidget::move()
)