Reputation: 133
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:
Upvotes: 4
Views: 7110
Reputation: 1
Another option might be:
from PyQt6.QtWidget import QComboBox
self.combobox = QComboBox()
self.combobox.setStyleSheet("QComboBox {combobox-popup: 0;}")
self.combobox.setMaxVisibleItems(n_items_you_like_to_display)
Upvotes: 0
Reputation: 73
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
Upvotes: 4
Reputation: 133
I solved it.
Add the following code.
#include <QAbstractItemView>
combobox.view().setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded).
Upvotes: 7