PDA

View Full Version : [Dock Widget] Dynamically overlayed DockWidget



maxilase
21st April 2015, 14:08
Hello Everyone !

I am trying to create a dynamical QDocWidget, and I was expecting it could be a native function but I didn't found it in the doc...

I have a QDockWidget which is designed horizontally (QHBoxLayout), I set its parameters so that it can be docked on any Area of my mainWindow.
What I would like is that :

It could be docked really everywhere (I actually can't dock it on left and right areas)
It would automatically change its layout according to the area its docked to


Is there a function or a parameter that can do this ?
Do i have to manually create a button that would switch the layout ?
Is there any Signal emited when trying to "re-dock" a QDockWidget ?

Thank you for your help.

anda_skoa
21st April 2015, 15:48
The dockwidget emits a dockLocationChanged() when it undocked or redocked

Cheers,
_

maxilase
23rd April 2015, 13:12
The dockwidget emits a dockLocationChanged() when it undocked or redocked

Cheers,
_

Thank you ! I managed to do what I wanted, I will explain my technique here maybe it can help someone.
I Subclassed QDockWidget and then wrote a new SLOT:

void MyQDockWidget::changeOrientation(Qt::DockWidgetAre a area) {
myLayout.clear;
switch(area) {
case Qt::TopDockWidgetArea:
//set my new layout here
break;
case Qt::BottomDockWidgetArea:
//set new Bot layout here
break
//do other layout if you need + default layout.
}
}

And then connected this slot with the mentionned above signal. It works great ! Thanks a lot.
I got to say that I am pretty suprised that it is not a native SLOT in Qt. I guess it is a rarely used function...

anda_skoa
23rd April 2015, 13:45
Not sure what you mean with native slot.
The signal is part of the public/native API of QDockWidget, isn't it?

Cheers,
_

Kryzon
27th April 2015, 00:05
For a perfectionist, something lacking in your dynamic layout system is that the "gap object" (that blue rectangle showing the future dock location and geometry) will not have the same dynamic layout as the final docked widget.
When you drag a vertical dock to the top or bottom regions, the blue preview region will have a certain geometry that is not reflected by the final dock geometry, which you're changing as soon as the dock is released.
This can be confusing \ frustrating for some users, so be prepared to receive bug reports on this.

Qt does have this dynamic layout for toolbars.

d_stranz
27th April 2015, 18:34
Not sure what you mean with native slot.
The signal is part of the public/native API of QDockWidget, isn't it?


I think he means: "Why isn't automatic layout reconfiguration a native part of Qt?" I think the answer to that should be pretty obvious.