質問

I have a dialog containing a QGridLayout with three columns. One of the rows contains a QComboBox, a QPushbutton, and another QPushButton in each column respectively. I want each column to be the same size and scale equally.

Unfortunately, the QComboBox is setting its size hint too large, to be big enough to contain its widest item. It appears there's no SizeAdjustPolicy called "DoNotAdjustAndStopBeingAnnoying" or similar, so I'm not sure if there's anything I can set to force it to stop doing this adjusting.

I know I can do this in code fairly easily, but I would prefer to keep this sort of detail in the .ui file. Is there any way I can do this in Qt 4.8 without writing any code?

役に立ちましたか?

解決

I was able to solve this by setting the horizontal component of the sizePolicy for the combo box to Ignored. That resulted in the combo box becoming able to be shrunk further than the buttons, so I changed them to also use Ignored and set the horizontal minimumSize for all 3 of the controls. Now they all start out at the same size, and are sized up and down with the layout equally, stopping at an appropriate minimum.

他のヒント

Do not override it in the ui file. Override it either with Qt Designer, in the property panel, or in the code, when you are constructing the object with direct access to the ui.

EDIT: Anyway it can be useful

There is hierarchy between QLayout::SizeConstraint, QWidget::minimumSizeHint, QWidget::minimumSize, and you can find it in the documentation.

  • QWidget::minimumSize is not set by default. When it is, it prevails over QWidget::minimumSizeHint
  • QWidget::minimumSizeHint is invalid if the widget is not in a layout (meaning that it can be resized to 0 with the mouse), otherwise use the one defined by the layout.
  • QLayout::SizeConstraint holds the default layout behavior of the widgets it *directly * manage. If you nest a layout A within a layout B, all widgets added to A will use its property. Also if a widget W in B define its own layout, then this layout constraints are the one to be applied for the widget W.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top