PDA

View Full Version : How to use QDockWidgets inside a QWidget ?



Comer352l
6th January 2011, 17:39
Hi,

how can I use QDockWidgets inside a QWidget (for example a QTabWidget) ?
I have seen the "Dock Widgets" example where a QMainWindow is used.
But QWidget doesn't have the addDockWidget() method.
Of course, I can add them like normal QWidgets, but then docking doesn't work as expected.
Any ideas ? Thanks !

Frank

high_flyer
6th January 2011, 23:09
I don't think you can, since AFAIK the dock area behavior is only implemented by QMainWindow.
If you want the docking behavior , you will have to implement it in the parent widget.

But maybe someone else knows better.

Lykurg
7th January 2011, 09:02
Simply use a QMainWindow instead of QWidet. QMainWindow is a normal QWidget so it could be used whereever you also can use a widget. There is no restriction to use QMainWindow only as the topmost widget.

Comer352l
7th January 2011, 13:30
Thank you so far !


Simply use a QMainWindow instead of QWidet. QMainWindow is a normal QWidget so it could be used whereever you also can use a widget. There is no restriction to use QMainWindow only as the topmost widget.
I can't, because I want to use it inside a QTabWidget. :(


I don't think you can, since AFAIK the dock area behavior is only implemented by QMainWindow.
If you want the docking behavior , you will have to implement it in the parent widget.
Is there a reason why it is only implemented in QMainWindow or do you think it could be added to QWidget, too ?
Then I could create a feature request...

Lykurg
7th January 2011, 13:51
I can't, because I want to use it inside a QTabWidget. :(Ehm, why not? QTabWidget::addPage() takes a pointer to a QWidget and since QMainWindow inherits QWidget it is perfectly possible.

Comer352l
13th January 2011, 13:39
Ehm, why not? QTabWidget::addPage() takes a pointer to a QWidget and since QMainWindow inherits QWidget it is perfectly possible.

Hmm, when I add the QmainWindow with addTab(), it works fine indeed, thanks.
I had the same idea, too, but tried to add it to an existing tab by setting the tabs wiget as parent:

QMainWindow *mw = new QMainWindow( myTabWidget->widget( tabNr ) )

For QWidgets, that's enough to embedd the content into the tab. But QMainWindows are still shown as separate windows...
Is there something else I have to do to embedd them ? Is there a deeper reason (apart from the fact that they are different classes ;) ) why QWidgets and QMainWindows behave differently here ?