Qt如何禁用QComboBox的鼠标滚动?

标签 qt scroll mouse qcombobox

我在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/

相关文章:

c++ - 由于槽和信号的错误使用导致程序崩溃

scroll - Chrome DevTools Mobile Emulation 滚动不起作用

c++ - SDL 鼠标点击

javascript - Firefox scrollTop 问题

java - Java中滚动后的矩形条

c# - 在C#中单击鼠标获取鼠标坐标

Vim:从鼠标过渡到移动

c++ - 如何在控制台应用程序的 mini2440 屏幕上打印我的应用程序的输出?

在另一个类中使用 ui 的 C++ QT 错误

c++ - Qt: "No such signal"错误