Reputation: 47
here is my code
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QBrush, QColor
import sys
class Ui_MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.comboBox = QComboBox(self)
self.comboBox.setStyleSheet('''
QComboBox QAbstractItemView {
padding: 5px;
border: 2px solid rgb(0, 0, 0);
}''')
self.comboBox.addItem("1")
self.comboBox.addItem("2")
self.comboBox.addItem("3")
self.comboBox.addItem("1")
self.comboBox.addItem("2")
self.comboBox.addItem("3")
self.comboBox.addItem("1")
self.comboBox.addItem("2")
self.comboBox.addItem("3")
self.comboBox.addItem("1")
self.comboBox.addItem("2")
self.comboBox.addItem("3")
self.comboBox.addItem("1")
self.comboBox.addItem("2")
self.comboBox.addItem("3")
self.comboBox.addItem("1")
self.comboBox.addItem("2")
self.comboBox.addItem("3")
self.comboBox.addItem("1")
self.comboBox.addItem("2")
self.comboBox.addItem("3")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
MainWindow = Ui_MainWindow()
MainWindow.show()
sys.exit(app.exec_())
but when I hover the mouse cursor over the place indicated by the red arrow, the list starts scrolling by itself
if from the QComboBox style
QComboBox QAbstractItemView {
padding: 5px;
border: 2px solid rgb(0, 0, 0);
}
remove these two lines, then this scrolling disappears. But I need to keep these two styles
Upvotes: 0
Views: 350
Reputation: 120578
The scrolling behaviour can be switched off by setting the auto-scroll property of the view:
self.comboBox.view().setAutoScroll(False)
Upvotes: 1