Przemek Lewandowski
Przemek Lewandowski

Reputation: 173

QDockWidget layout with no central widget

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:

qtdesigner

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?

Upvotes: 4

Views: 3726

Answers (4)

Gypaets
Gypaets

Reputation: 125

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.

Upvotes: 0

tomasz74
tomasz74

Reputation: 16661

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

Upvotes: 0

Thiago Cavalcanti
Thiago Cavalcanti

Reputation: 523

You can remove centralWidget using setCentralWidget(0);

Upvotes: 3

ekhumoro
ekhumoro

Reputation: 120578

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.

Upvotes: 1

Related Questions