Unsolved How to split QDockWidgets with equal size?
-
In my application I allow the user to split docks vertically or horizontally, using splitDockWidget(), so if the user splits the first dock and then splits again the two it can get 2x2 docks of equal size without having to adjust them.
Horizontally, splits get equal width. However, when I split vertically, the second dock gets no height Oo
I searched on the web and essentially found doc quotes recommending to set size policies in the widget inside the QDockWidget.
But I have no idea how to tell "take half the space when splitting a dock" with these policies :(
I tried to resize the content before docking, no effect at all.
I also don't get why it works only horizontally...How can I do this?
-
Hi,
No height ?
Can you provide a minimal code sample that shows that behavior ?
-
@SGaist By "no height", I mean it's tiny, or has a zero-height.
I reproduced the behaviour with this code:Header
class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void splitDockHorizontal(); void splitDockVertical(); private: QDockWidget * m_dock1; };
Implementation
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setDockNestingEnabled(true); m_dock1 = new QDockWidget("Dock 1", this); addDockWidget(Qt::LeftDockWidgetArea, m_dock1); QWidget * dock1Content = new QWidget(this); QVBoxLayout * boxLayout = new QVBoxLayout(); dock1Content->setLayout(boxLayout); QPushButton * btnH = new QPushButton("SplitH", dock1Content); QPushButton * btnV = new QPushButton("SplitV", dock1Content); boxLayout->addWidget(btnH); boxLayout->addWidget(btnV); connect(btnH, SIGNAL(clicked()), this, SLOT(splitDockHorizontal())); connect(btnV, SIGNAL(clicked()), this, SLOT(splitDockVertical())); m_dock1->setWidget(dock1Content); } MainWindow::~MainWindow() { } void MainWindow::splitDockHorizontal() { QWidget * content = new QWidget(this); QDockWidget * dock = new QDockWidget("Dock +", this); dock->setWidget(content); splitDockWidget(m_dock1, dock, Qt::Horizontal); } void MainWindow::splitDockVertical() { QWidget * content = new QWidget(this); QDockWidget * dock = new QDockWidget("Dock +", this); dock->setWidget(content); splitDockWidget(m_dock1, dock, Qt::Vertical); }
-
That's because when you create your new widget they are empty so splitting horizontally you have the height of m_dock1 that also applied to your newly created dock however when splitting vertically only the width will be used.
-
@SGaist I know my widget is empty, however it should not prevent it from getting half the size. In my use case, it actually contains a native window (with no Qt widget inside), which has no preferred size. If I were to put it floating, maybe I could set it a size, but here I'm clueless. That's why I also tried to resize it before docking, but it doesnt works...
-
In that case you should settle for a size you know is good for that window and set it on the widget