1

I have a standard QComboBox using PySide with fairly long item names, which gets truncated for some reason on Windows, but not in Ubuntu (Gnome). I have only set it with:

self.ConfChoose = QtGui.QComboBox()
self.ConfChoose.addItem('blablablabla')

etc. No extra policy settings.

Screenshot Windows

Screenshot Ubuntu

Any ideas as to why, and how I can make the items not get truncated? I can set the size of the QComboBox to the size of the longest text string, but that is not a solution. It should just behave like on Ubuntu.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Termo
  • 71
  • 5
  • 1
    It should not behave like on Ubuntu because the Windows style acts like native Windows controls would. You can probably change that behavior, but it all comes from the style system. It has nothing to do with the size of the widget itself. – Kuba hasn't forgotten Monica Aug 24 '16 at 13:34
  • You can create your own list view and use [`QComboBox::setView`](http://doc.qt.io/qt-5/qcombobox.html#setView) to set it to your combo box. Or you can modify the existing list view by using [`QComboBox::view`](http://doc.qt.io/qt-5/qcombobox.html#view) to get the list view. – thuga Aug 25 '16 at 07:54
  • Thank you both for the directions. Yes appearently it is something native to the windows view (simple test in Qt Deigner with preview in Gtk and Windows show the same behaviour). The QComboBox.view() has a lot of things, and I'm not sure where this menu size rule is set. Any help for which property I should be looking at? – Termo Aug 25 '16 at 08:55

1 Answers1

3

Finally got a solution I can accept:

self.ConfChoose = QtGui.QComboBox()
[self.ConfChoose.addItem(name) for name in self.listOfStrings]
w=self.ConfChoose.fontMetrics().boundingRect(max(self.listOfStrings, key=len)).width()
self.ConfChoose.view().setFixedWidth(w+10)

Thank you for the input to get in the right direction...

Termo
  • 71
  • 5