【发布时间】:2018-12-16 16:40:42
【问题描述】:
我一直在环顾四周,似乎找不到任何可以帮助我在QTableView 中更改滚轮滚动方向的示例。这是我最好的尝试。
这是我在水平滚动时所做的:
def eventFilter(self, obj, event):
#some of my widgets are disabled, I can simply do another if for enabled ones
if obj and obj.isEnabled() and event.type() == QEvent.Wheel and self.shift_key:
newEvent = QWheelEvent(obj.mapToParent(event.pos()), event.globalPos(),
event.delta(), event.buttons(),
event.modifiers(), 1)
QApplication.instance().postEvent(obj.parent(), newEvent)
return True
if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Shift:
self.shift_key = True
return True
elif event.type() == QEvent.KeyRelease and event.key() == Qt.Key_Shift:
self.shift_key = False
return True
return QObject.eventFilter(self, obj, event)
当我将鼠标悬停在标题或空白处时会出现问题,因为它不会水平滚动并且还会显示错误提示
QApplication::postEvent: Unexpected null receiver
如何使用scroll + shift 实现水平滚动?
【问题讨论】:
标签: python python-2.7 pyqt pyqt4 qtableview