PDA

View Full Version : Is it possible to put three QDockwidgets side by side?



winkle98
15th September 2011, 02:35
I have an QMainWindow that has no central widget. Based on suggestions here I've setDockNestingEnable(true) and set the dock widgets to allow Qt::AllDockWidgetAreas. For the most part this is working as desired. However, I'd like to line my dock widgets up 3 across.

i.e.

DockWidgetA DockWidgetB DockWidgetC

Is this possible?

ChrisW67
15th September 2011, 02:53
Yes, it's even the default behaviour (at least on Linux). What is the problem?



#include <QtGui>
#include <QDebug>

class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
setGeometry(0, 0, 640, 480);

setDockNestingEnabled(true);
QDockWidget *dock1 = new QDockWidget(tr("Dock 1"), this);
dock1->setAllowedAreas(Qt::AllDockWidgetAreas);
QDockWidget *dock2 = new QDockWidget(tr("Dock 2"), this);
dock2->setAllowedAreas(Qt::AllDockWidgetAreas);
QDockWidget *dock3 = new QDockWidget(tr("Dock 3"), this);
dock3->setAllowedAreas(Qt::AllDockWidgetAreas);
addDockWidget(Qt::TopDockWidgetArea, dock1);
addDockWidget(Qt::TopDockWidgetArea, dock2);
addDockWidget(Qt::TopDockWidgetArea, dock3);
// No central widget
}
public slots:
private:
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"

winkle98
24th September 2011, 00:03
Thank you,

I missed one of the setAllowedAreas calls.