How to resize QMainWindow after removing all DockWidgets?

◇◆丶佛笑我妖孽 提交于 2019-12-05 07:58:59

Options

a) You can overload sizeHint() a virtual function. Let it return the size you want for your main window.

b) In the main window's constructor you can call setMinimumSize() and setMaximumSize() one after another, both with the the desired main window size. If you keep both same you get a fixed size.

c) Take a look at layout()->setResizeMode(Fixed).

It looks like you misunderstood the meaning of the QMainWindow.sizeHint() method.

According to QWidget.sizeHint() documentation (from which QMainWindow inherits):

This property holds the recommended size for the widget.

If the value of this property is an invalid size, no size is recommended. The default implementation of sizeHint() returns an invalid size if there is no layout for this widget, and returns the layout's preferred size otherwise.

To get the actual size of your window, you should use the QMainWindow.geometry() method instead, which gives all the informations about the widget size and position:

win_geo = self.geometry()
win_top = win_geo.top()
win_bottom = win_geo.bottom()
win_left = win_geo.left()
win_right = win_geo.right()
win_width = win_geo.width()
win_height = win_geo.height()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!