PDA

View Full Version : set QLayout to QDockWidget



WilliamSpiderWeb
3rd March 2011, 22:34
I'm going to create a modified class of QDockWidget (lets call the class QAlexDockWidget) and place several objects of that class on my MainWindow during my App is running. The design of that class should be defined by layouts.

This is a function of the class QAlexDockWidget


void QAlexDockWidget::setLayout_List()
{
QVBoxLayout *vLayout = new QVBoxLayout;
QHBoxLayout *hLayout = new QHBoxLayout;
QListView *listView = new QListView;
QPushButton *btnNew = new QPushButton;
QPushButton *btnDel = new QPushButton;
QPushButton *btnEdit = new QPushButton;
hLayout->addWidget(btnNew);
hLayout->addWidget(btnDel);
hLayout->addWidget(btnEdit);
vLayout->addWidget(listView);
vLayout->addLayout(hLayout);
this->setLayout(vLayout);
}


My problem is, when i run the application the AlexDockWidget is still empty and I get the debugger message



QWidget::setLayout: Attempting to set QLayout "" on QAlexDockWidget "Titelleiste", which already has a layout


Why is there an existig layout and how could I place my own layout instead of this default layout?

ChrisW67
4th March 2011, 05:23
You apply this layout to your own QWidget and then use QDockWidget::setWidget() to make that the widget that QDockWidget is wrapping.

WilliamSpiderWeb
4th March 2011, 12:15
If I understand you the right way, I should do something like that.



void QAlexDockWidget::setLayout_List()
{
QWidget *widLayout = new QWidget;
QVBoxLayout *vLayout = new QVBoxLayout;
QHBoxLayout *hLayout = new QHBoxLayout;
QListView *listView = new QListView;
QPushButton *btnNew = new QPushButton;
QPushButton *btnDel = new QPushButton;
QPushButton *btnEdit = new QPushButton;
hLayout->addWidget(btnNew);
hLayout->addWidget(btnDel);
hLayout->addWidget(btnEdit);
vLayout->addWidget(listView);
vLayout->addLayout(hLayout);
widLayout->setLayout(vLayout);
this->setWidget(widLayout);

}


Isn't it?

WilliamSpiderWeb
4th March 2011, 23:29
Yeah, that works.