Setting different sizes to tabified QDockWidget?
-
Hi,
I have some QDockWidgets objects that was tabified. Now I want to have sth like this:- when one of the tabs is active I can resize that docked widget (I'm changing only height of it, width is the same as mainwindow)
- then for example I change to other tab and resize that docked widget (to different height than first dock widget)
- then I back to previous tab and I want to have that dock widget in size I left it, not in size of second tab
Is it possible to do this?
-
Hi,
What you could try is to keep a hash containing your QDockWidget pointers as key and their corresponding heights as value, then add a slot to your QMainWindow that reacts on the visibility changed signal of QDockWidget and update the size of the newly visible widget.
Hope it helps
-
I have tried to do this by saving last height of QDockWidget but I can't resize QDockWidget. Somewhere I read that there is problem with resizing QDockWidget because QMainWindow controls it's size (or sth common).
EDIT:
Ok, solved. It was enough to set maximum and minimum size to previous saved size and then add processEvents() and return to max and min default values.@
void MyDockWidget::setDockSize(bool isVisible)
{
if(isVisible)
{
if(m_firstUse)
m_firstUse = false;setMaximumHeight(m_previousHeight); setMinimumHeight(m_previousHeight); QApplication::processEvents(); setMaximumHeight(m_defaultHeight); setMinimumHeight(1); } else { if(m_firstUse) m_previousHeight = 1; else m_previousHeight = size().height();
}
@
I'm only wondering why I have to set minimum height to 1, I can't set it to 0 because then signal visibilityChanged(bool) is not called. And this signal is linked with my slot setDockSize.
-
Probably because a size of zero implies that your widget is invisible
-
Maybe you are right. For now, I leave minimum size set to 1. Maybe I will think about solve this problem later.