我在QTableView中有一些嵌入式QComboBox。为了使它们默认显示,我将这些索引设置为“持久编辑器”。但是现在每次我在它们上面滚动鼠标时,它们都会破坏我当前的表选择。
因此,基本上我该如何禁用QComboBox的鼠标滚动?
最佳答案
当我找到这个问题时,当我试图找出(基本上)相同问题的解决方案时:就我而言,我想在pyside的QScrollArea中使用一个QComboBox(python QT lib)。
这是我重新定义的QComboBox类:
#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)
可以这样调用:
self.scrollArea = QtGui.QScrollArea(self)
self.frmScroll = QtGui.QFrame(self.scrollArea)
cmbOption = MyQComboBox(self.frmScroll)
基本上是emkey08's answer中的link Ralph Tandetzky pointed out,但这一次是在python中。
关于Qt如何禁用QComboBox的鼠标滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3241830/