Mikhail
Mikhail

Reputation: 47

how to remove scrolling of the QComboBox element?

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_())

enter image description here

but when I hover the mouse cursor over the place indicated by the red arrow, the list starts scrolling by itself

enter image description here

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

Answers (1)

ekhumoro
ekhumoro

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

Related Questions