Qt How to disable QComboBox mouse scrolling?

I have a built-in QComboBox in a QTableView. To show them by default, I made these indexes a "permanent editor." But now, every time I scroll the mouse, they break my current table selection.

So basically, how can I disable QComboBox mouse scrolling?

+6
qt scroll mouse qcombobox
source share
3 answers

The same thing can happen to you in a QSpinBox or QDoubleSpinBox . On the QSpinBox inside QScrollArea: how to prevent the Spin Box from stealing focus when scrolling? you can find a really good and well-explained solution to the problem with code snippets.

+4
source share

You can disable mouse wheel scrolling by setting eventFilter to your QComboBox and ignore events generated by the mouse wheel, or subclass QComboBox and redefine wheelEvent to do nothing.

+2
source share

How did I find this question when I tried to figure out a solution to (basically) the same problem: In my case, I wanted to have a QComboBox in QScrollArea in pyside (python QT lib).

Here is my overridden QComboBox class:

 #this combo box scrolls only if opend before. #if the mouse is over the combobox and the mousewheel is turned, # the mousewheel event of the scrollWidget is triggered class MyQComboBox(QtGui.QComboBox): def __init__(self, scrollWidget=None, *args, **kwargs): super(MyQComboBox, self).__init__(*args, **kwargs) self.scrollWidget=scrollWidget self.setFocusPolicy(QtCore.Qt.StrongFocus) def wheelEvent(self, *args, **kwargs): if self.hasFocus(): return QtGui.QComboBox.wheelEvent(self, *args, **kwargs) else: return self.scrollWidget.wheelEvent(*args, **kwargs) 

which can be called as follows:

 self.scrollArea = QtGui.QScrollArea(self) self.frmScroll = QtGui.QFrame(self.scrollArea) cmbOption = MyQComboBox(self.frmScroll) 

Basically the answer is emkey08 in the link Ralph Tandecki talked about , but this time in python.

+2
source share

All Articles