QDockWidget layout with no central widget

六眼飞鱼酱① 提交于 2019-12-10 16:17:49

问题


I have a problem with QDockWidget. I'm using Qt Designer, and I would like to build an app with only dock-widgets, and have a small bar above for properties. The problem is that I cannot build the app without a main QWidget (I mean with only QDockWidgets).

Here is my screenshot:

Annotation 1) - this is the space that I can't remove. When I remove it from xml, Qt Designer crashes. If it is not removable, how can I set the left QDockWidget and the right QDockWidget to have half of the entire window width?


回答1:


You can remove centralWidget using setCentralWidget(0);




回答2:


This cannot be done from within Qt Designer. However, there is a Qt Forum Thread which suggests there may be a way to do it programmatically.

Firstly, you have to set the main-window dockNestingEnabled property to true in Qt Designer. Then, after you create the ui, programmatically delete the central widget, and then also remove, re-add and re-show all the dock widgets.

When I tested this, I found that I needed to show the dock-widgets with a single-shot timer, otherwise I couldn't resize them vertically. However, even with that little hack, I still found that resizing doesn't always work properly. So I'm not convinced that Qt really supports this way of using dock-widgets.




回答3:


After creating GUI in Qt Designer and translating it to ui_file. Add one line in your __init___ call script:

self.ui.centralwidget.hide()

you may need to check if your central widget is called the as above




回答4:


Remove all references to the central widget:

pyuic5 -x uifile.ui -o main.py
sed -i /centralwidget/d main.py

Running python3 main.py should get you the desired behaviour.



来源:https://stackoverflow.com/questions/33369854/qdockwidget-layout-with-no-central-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!