View Full Version : Popup of QComboBox wider than combobox?

20th October 2016, 11:33
Hi, I have a combobox with a fixed size (it is inside a QTableWidget cell) and enough entries to need a scrollbar.
I would like the popup of the combobox to be wider than the combobox itself (see attached image for a rough example). Is this possible?
I tried
- QComboBox::setSizeAdjustPolicy (QComboBox::AdjustToContents), but this also changes the width of the combobox and not only the popup's width
- QAbstractItemView::setTextElideMode (Qt::ElideNone) on the view() of the combobox. Now the text of the entries isn't elided anymore but the size of the popup does not change, so the scrollbar is above part of the text
- QWidget::setGeometry() on the view(). It looks like this resized something internally, because the scrollbar disappeared, but the popup itself is still the same size, so I cannot read the whole text of the entries
- an ItemDelegate on the view() that reimplements sizeHint(), but this had no effect at all.

I'm out of ideas now. Is this possible at all? Any further suggestions?


edit: I could not set elideMode in designer, so just imagine the image without the elided text in the popup.

20th October 2016, 15:53
You can set the minWidth property of the combobox's view. One way to do this is with a stylesheet. Another way is to calculate the largest text width of all items (utilizing font metrics) and then set the width of the view accordingly. The latter needs to be done as soon as an item is added/removed.

21st October 2016, 10:40
Thanks, this works.