PDA

View Full Version : Add QWidget to QDockWidget



Jack_Holmes
18th December 2015, 12:44
Hello. I am trying to add a QPushButton dynamically.



QPushButton* pushButton = new QPushButton(m_pUI->dockSelectionView);
pushButton->setObjectName(QStringLiteral("pushButton"));
pushButton->setGeometry(QRect(60, 140, 75, 23));
m_pCogSparkzEditorClass->layout()->addWidget(pushButton);


This adds a button, but not to the dock widget.

If I add a QPushButton in the designer, when I change the size of the docked widget the button moves accordingly.
But when I try to add it in code, passing the parent in the constructor - it behaves as if I just added it to the QMainWindow and not to the dock widget.

So my questions is: How do I add a QWidget to a QDockWidget?

Many thanks, Jack.

anda_skoa
18th December 2015, 13:15
You are adding the button to the layout of "m_pCogSparkzEditorClass", so it gets reparented to whatever that widget is.

Cheers,
_

Vikram.Saralaya
18th December 2015, 13:17
void QDockWidget::setWidget(QWidget * widget)