PyQt QComboBox和QSpinBox禁止鼠标滚动
 自定义控件代码Qt Designer操作方法
 
自定义控件代码
 
新建 custom_widget.py文件,内容如下:
 
from PyQt5.QtCore import QEvent
from PyQt5.QtWidgets import QComboBox, QSpinBox
class CustomQCB(QComboBox):
    def wheelEvent(self, e):
        if e.type() == QEvent.Wheel:
            e.ignore()
class CustomQSB(QSpinBox):
    def wheelEvent(self, e):
        if e.type() == QEvent.Wheel:
            e.ignore()
 
这里对原有类中的方法进行了重写。
 
Qt Designer操作方法
 
接下来在Qt Designer中对控制进行操作:
 
 选择要禁用鼠标滚动的控件,右键选择 Promote to …; 
  在弹出的 Promoted Widgets 窗口中,添加刚才新建的类和文件名,保存Ui文件;
  将其它需要禁用的控件进行提升 
  
完成后保存文件,重新将Ui文件转换为Py文件即可。