问题
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