15

I've got a complex dialog, and it is full of whitespace and I can't shrink it. In Designer, it has lots of components that then get dynamically hidden, and a few which are dynamically added. I've added dumping of size policies, size hints, and minimum sizes, but still can't figure out why Qt won't let me drag it smaller.

There must be some tools or techniques for troubleshooting this.

Please share.

Mike Elkins
  • 1,408
  • 1
  • 11
  • 12

5 Answers5

4

I don't know of any tools for doing this, but I have managed it before by changing the palette of the different elements in the dialog, then looking at what is taking up more (or less) room than I expected, and focusing my investigation on those elements.

In a more general sense, make sure you've set the dialog to not be a fixed size. That bit me once as well.

Caleb Huitt - cjhuitt
  • 14,785
  • 3
  • 42
  • 49
3

You could capture QApplication::focusChanged(QWidget*,QWidget*) signal and change the background of currently focused widget. I think this would help to determine how much space each widget occupies.

Sebastian Dusza
  • 2,470
  • 2
  • 30
  • 54
1

Sounds like we could use the equivalent of Firebug's element and CSS metrics inspector modes. The hardest part of such a tool would be effectively figuring out and communicating why an individual layout policy was using or not using a given size value in a widget.

1

It's hard to tell without seeing your layout, but I see a lot of resize problems like you describe due to using QGridLayout. The largest thing in a column or row, is going to determine the minimum width of that column. The same for a row.

If you are using QGridLayout, you might try making things span columns/rows.

I'd also recommend trying all your various layout configurations in Designer and test it by resizing. We don't actually use Designer where I work, but I use it all the time to test, and debug layout ideas.

Michael Bishop
  • 4,240
  • 3
  • 37
  • 41
0

Lots of trial and error. I have discovered that inserting stretches in strategic spots often helps me produce the effect I want. For example, if I have a QPushButton in a layout that I want to be the minimum size I will do something like the following:


QHBoxLayout* layout = new QHBoxLayout;
QPushButton* myBtn = new QPushButton("Test");

layout->insertStretch(1);
layout->addWidget(myBtn, 0);
layout->insertStretch(1);

Also, don't forget that you can set the contents margin of a layout with setContentsMargins().

I don't use Designer as I have discovered I understand the layout system much better when I play around with it in code.

Chris
  • 619
  • 2
  • 9
  • 18