3

I use python, and qt5, and qt designer. I want to add a scroll bar to the combo box. Any way to add a scrollbar using style-sheet? Other ways are also good.

This is the style-sheet currently used in the combo box.

QComboBox { 
    combobox-popup: 0;
}

I use this because I want to show the drop down list in 10 order. There seems to be no more data below because there are no scrollbars at this time.

If you know how, Please help me.

This is the situation now:

But I want:

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
semikim
  • 123
  • 1
  • 9

2 Answers2

7

I solved it.

Add the following code.

#include <QAbstractItemView>
combobox.view().setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded).
Em.MF
  • 303
  • 3
  • 11
semikim
  • 123
  • 1
  • 9
3

I used it in Python as follows:

from PyQt5.QtCore import Qt
self.combobox.view().setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)

and a Stylesheet with:

QComboBox {
    combobox-popup: 0;
}

thanks for this solution

dragonfly
  • 53
  • 3
  • Hey, is there a way I can add this "setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)" property in QtDesigner, so that it automatically generates python code – Priya Apr 22 '21 at 15:00