PyQT4 WheelEvent? how to detect if the wheel have been use?

可紊 提交于 2019-12-02 04:12:11

I might be a little confused on your question, but here's an example on how to get access to wheel events that resize your window. If you're using a QScrollArea I don't know why you would want to do this though.

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_())

If you look at the documentation for QScrollArea you'll see the line of inherited from the QWidget class which has a function called wheelEvent. You can put that in and overwrite the inherited function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!