PDA

View Full Version : setLayout to QDockWidget



hemrajn
21st April 2009, 11:57
hi all,

i am new to QT programming, i want to create a Dockwidget and it contain some label and text box layout, for that i create a QDockwidget object and i create QGridLayout object and addWidget as label and text box.

while setting the layout to dockwidget it not showing the layout.
here my code:


dwidget = new QDockWidget(tr("&Name"), this);
dwidget->setAllowedAreas(Qt::AllDockWidgetAreas);
dwidget->setFeatures(QDockWidget::DockWidgetMovable|QDockWi dget::AllDockWidgetFeatures);
dwidget->setObjectName("NEW Widget");
dwidget->setWindowTitle("NewDock");

label1 = new QLabel("Name: ");
txtEdit = new QLineEdit;

mainLayout = new QGridLayout();
mainLayout->addWidget(label1, 0, 0);
mainLayout->addWidget(txtEdit, 0, 1);

dwidget->setLayout(mainLayout);

addDockWidget(Qt::RightDockWidgetArea, dwidget);

it complies success but while running the program its not showing any layout on dockwidget.

is there any solution for this?

Regards.
hemraj

jpn
21st April 2009, 11:58
You cannot install a layout on QDockWidget. You must install the layout on another widget and call QDockWidget::setWidget().

hemrajn
21st April 2009, 12:17
Hi jpn,

i created another widget and setlayout to that widget, using the dockwidget object i set widget.
but still it not visible.
here my code:


QWidget newWidget(this);
newWidget.setLayout(mainLayout);

dwidget->setWidget(&newWidget);
dwidget->show();
addDockWidget(Qt::RightDockWidgetArea, dwidget);

Regards,
hemraj

jpn
21st April 2009, 12:21
If you create the widget on the stack, it will go out of scope according to normal C++ rules.

PS. Please start using code-tags. I already sent you instructions. Thank you.

spirit
21st April 2009, 12:22
and you will get nothing :)
try this


QWidget *newWidget = new QWidget(this);
newWidget->setLayout(mainLayout);

dwidget->setWidget(newWidget);
dwidget->show();
addDockWidget(Qt::RightDockWidgetArea, dwidget);