当我发现这个问题时,当我试图找出(基本上)同样问题的解决方案时:在我的情况下,我想在pyside(python QT lib)的QScrollArea中有一个QComboBox.
这里是我重新定义的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)
Run Code Online (Sandbox Code Playgroud)
以这种方式可调用:
self.scrollArea = QtGui.QScrollArea(self)
self.frmScroll = QtGui.QFrame(self.scrollArea)
cmbOption = MyQComboBox(self.frmScroll)
Run Code Online (Sandbox Code Playgroud)
它基本上是emkey08的回答,链接Ralph Tandetzky指出,但这次是在python中.
同样的情况也可能发生在 aQSpinBox或 中QDoubleSpinBox。在QScrollArea 内的 QSpinBox 上:如何防止 Spin Box 在滚动时窃取焦点?您可以使用代码片段找到一个非常好的解释清楚的解决方案。
| 归档时间: |
|
| 查看次数: |
9485 次 |
| 最近记录: |