May 7, 2012

HeatherKM HeatherKM
Lab Rat
1 posts

How to default to the smallest possible size for a QDockWidget?

 

I have the following code:

  1.   QWidget *mainVSubsetWidget = new QWidget;
  2.   mainVSubsetWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
  3.   QVBoxLayout *mainVSelectLayout = new QVBoxLayout;
  4.   QVBoxLayout *cubeVolSelectLayout = new QVBoxLayout;
  5.   QVBoxLayout *buttonVolSelectLayout = new QVBoxLayout;
  6.   d_voxSubset = d_3dWidget->geoContext()->newCube();
  7.   QWidget * selectWidget = d_voxSubset->infoWidget();
  8.   cubeVolSelectLayout->addWidget(selectWidget);
  9.   mainVSelectLayout->addLayout(cubeVolSelectLayout);
  10.   QPushButton *resetVolSelectButton = new QPushButton("Reset");
  11.   buttonVolSelectLayout->insertWidget(0,resetVolSelectButton,0,Qt::AlignHCenter);
  12.   connect(resetVolSelectButton,SIGNAL(clicked()),this,SLOT(resetVSubset()));
  13.   mainVSelectLayout->addLayout(buttonVolSelectLayout);
  14.   resetVolSelectButton->setDefault(true);
  15.   mainVSubsetWidget->setLayout(mainVSelectLayout);
  16.   d_dockVSubset = new QDockWidget("V Subset",this);
  17.   d_dockVSubset->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
  18.   d_dockVSubset->setWidget(mainVSubsetWidget);
  19.   addDockWidget(Qt::LeftDockWidgetArea, d_dockVSubset);
  20.   showVSubset(0);

So the widget is hidden by default. When I first open it up, it looks like this docked:
initial docked [docs.google.com]
and this undocked:
initial undocked [docs.google.com]
I can grab the corner or resize bar and make it smaller, to this size:
minimum docked [docs.google.com]
and this:
minimum undocked [docs.google.com]
How do I do that in code? I want it to be shown as small as possible in the width direction, but be able to grow as needed when docked, if other docked widgets are added that are wider.

I’m fairly new to Qt, and I have looked through the documentation and looked at using the sizeHint and such, but I’m not getting anything to work, so I must be missing something.

Thanks for the help,
HeatherKM

0 replies

 
  ‹‹ [SOLVED] (Beginner) Very simple XML Parser      mousePressEvent goes to Parent when pop up is visible ››

You must log in to post a reply. Not a member yet? Register here!