问题描述
我正在尝试进行以下设置:
I am trying to have following setup:
在开始时(当主窗口打开时)我想在左边有 2 个 QDockWidgets,宽度为 400px,高度为 QMainWindows 高度的 1/2(每个).在左侧,3 个 QDockWidgets,宽度为 400px,高度为 QMainWindows 高度的 1/3(每个).所有 5 个小部件都必须调整大小.这意味着在这种情况下使用 setFixSize()
将不起作用.
at start (when main window is opened) I want to have 2 QDockWidgets at left with width 400px and height 1/2 (each) of QMainWindows height. At the left, 3 QDockWidgets with width 400px and height 1/3 (each) of QMainWindows height. All of 5 widgets have to be resizable. That means using setFixSize()
won't work in this case.
到目前为止,我已经尝试在设计中更改 Geometry>Width
和 Geometry>Height
-> 没有用.
So far I've tried changing Geometry>Width
and Gemetry>Height
in designed -> didn't work.
然后我尝试在主窗口构造函数中使用 resize()
但它也不起作用.
Then I tried using resize()
in main window constructor but it didn't work either.
为什么Gemetry>Height/Width
和resize()
对widget 的大小以及如何实现上述的主窗口布局没有任何影响?
Why doesn't Gemetry>Height/Width
and resize()
have any influence on widgets size and how to achieve main window layout as described above?
推荐答案
停靠小部件将被添加到主窗口的布局中,因此调整它们的大小将不起作用.一种解决方法是重新实现添加到每个停靠小部件的内容小部件的 sizeHint
.
The dock-widgets will be added to the layout of the main-window, so resizing them will have no effect. One work-around for this is to reimplement the sizeHint
of the content widget that is added to each dock-widget.
我想另一种看待这个的方式是让用户以他们喜欢的任何方式排列停靠小部件,然后使用 saveState 和 restoreState 来管理初始状态.
I suppose another way of looking at this is to let the user arrange the dock-widgets in whatever way they prefer, and then use saveState and restoreState to manage the initial state.
这篇关于Qt 5.7 QDockWidget 默认大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!