pyqt pyside qcombobox disable wheel scrolling,去除滚轮改变值和获取焦点功能

pyqt pyside qcombobox disable wheel scrolling,去除滚轮改变值和获取焦点功能

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

posted @ 2019-09-03 17:58  ibingshan  阅读(1684)  评论(0编辑  收藏  举报