QComboBox AdjustToContents changing height

7k Views Asked by At

I'm trying to set a QComboBox to have expanding height, but adjusting to contents length.

The combo is created like this:

self.dataentrycombo = QComboBox()
self.dataentrycombo.setIconSize(QSize(48,48))
self.dataentrycombo.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
self.dataentrycombo.setSizeAdjustPolicy(QComboBox.AdjustToContents)
self.dataentrycombo.setModel(self.dataentrymodel)

After I populate my model, the size adjusts, but the height is smaller than the toolbar that the combobox lives in:

enter image description here

If I change my main window size then it will expand fully:

enter image description here

I have tried using QComboBox.AdjustToMinimumContentsLengthWithIcon, but then it just looks like this:

enter image description here

My model items are created like this:

    item = QStandardItem(QIcon(form.icon), form.icontext)
    item.setData(form, Qt.UserRole + 1)
    self.dataentrymodel.appendRow(item)

Extra Info:

  • Qt: 4.7
  • Windows 7 and 8
1

There are 1 best solutions below

0
On

I was able to fix it using:

    self.dataentrycombo.setMinimumHeight(self.projecttoolbar.height())

It's a bit of a dirty hack but it works OK for now.