Search code examples
qtscrollbarqcombobox

qt qcombobox shows no scroll bar


I have a QComboBox with an underlying model. Sometimes the model gets a couple of hundred of items, which makes it very difficult to scroll through the combobox. Is it somehow possible to add a scroll bar to the QComboBox? This would help a lot because my items are sorted.

I have read that QComboBox should come with a scroll bar by default, but this is not true in my case on my linux system. Is this the case with windows?

Best regards


Solution

  • QComboBox uses an QAbstractItemView (by default a QListView I think) for its popup. It's possible to call view() to get that widget. Since QAbstractItemView descends from QAbstractScrollArea, you can use all features from that class to modify how you want the scrollbars to show up.

    As an extra, you can change this view to another type. For instance I have used a QTreeView in the past since it fit better with the data.