PyQt4的WheelEvent从孩子父母
问题描述:
嗨,我的问题是有关这一点:在Qt Designer中创建PyQT4 WheelEventPyQt4的WheelEvent从孩子父母
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class Main(QWidget):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
layout = QHBoxLayout(self)
layout.addWidget(Scroll(self))
class Scroll(QScrollArea):
def __init__(self, parent=None):
super(Scroll, self).__init__(parent)
self.parent = parent
def wheelEvent(self, event):
super(Scroll, self).wheelEvent(event)
print "wheelEvent", event.delta()
newHeight = self.parent.geometry().height() - event.delta()
width = self.parent.geometry().width()
self.parent.resize(width, newHeight)
app = QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
我的卷轴类,我必须把它
没有访问是否有任何机会,有访问PyQT WheelEvent的滚动类,但在主类?
答
使用event-filter:
class Main(QWidget):
def __init__(self, parent=None):
...
self.scroll.installEventFilter(self)
def eventFilter(self, source, event):
if event.type() == QEvent.Wheel and source is self.scroll:
print "wheelEvent", event.delta()
newHeight = self.geometry().height() - event.delta()
width = self.geometry().width()
self.resize(width, newHeight)
# return True to consume the event
return False
return super(Main, self).eventFilter(source, event)
谢谢。必须是正确答案。可能你有一些想法,我可以找到有关事件过滤器的良好PYQT文档?或者建议阅读一些书籍来了解QT文档? – 2015-02-08 12:55:53
顺便找到了关于此的书。可能对某人有用 [link](https://books.google.com.ua/books?id=igcZ-fnxTwEC&pg=PA466&lpg=PA466&dq=pyqt+eventfilter&source=bl&ots=o1hpEfPSjB&sig=W-zKcSyQLoH7eN4BWhkpqSRXDhI&hl=ru&sa=X&ei= _FrXVPToOqSjyAOl3YGABw&VED = 0CDwQ6AEwBDgK#v = onepage&q = PyQt的%20eventfilter&F =假) – 2015-02-08 13:02:28