from PyQt5 import QtWidgets, QtCore

class CustemComboBox(QtWidgets.QComboBox):
    def __init__(self, parent = None):
        super(CustemComboBox,self).__init__(parent)

self.setFocusPolicy(QtCore.Qt.StrongFocus)
def wheelEvent(self, e):
e.ignore()
pass

这样之后,qcombobox 使用中键滚轮的时候就不会再改变当前值了,而且滚轮中键滚动,也不会影响其所在的scroll控件滚动(如果有的话)

改方式同样适应于有wheelEvent的类,例如QSpinBox和QDoubleSpinBox

如果不想自定义一个新的comboBox,可以这样:yourComboBox.wheelEvent = lambda e:e.ignore()

相关文章:

  • 2021-06-25
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-05-18
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2022-01-15
  • 2022-01-09
  • 2021-07-02
相关资源
相似解决方案