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

后端 未结 1 540
一个人的身影
一个人的身影 2021-01-25 09:45

im trying to find out in PyQT how can i set the Mousewheel event? i need it so i can attach it to the Qscroll area

the code im using is working fine. but the size is ha

相关标签:
1条回答
  • 2021-01-25 10:43

    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.

    0 讨论(0)
提交回复
热议问题