Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyQT4 WheelEvent?如何检测车轮是否已被使用?_Python_Scroll_Height_Pyqt4_Mousewheel - Fatal编程技术网

Python PyQT4 WheelEvent?如何检测车轮是否已被使用?

Python PyQT4 WheelEvent?如何检测车轮是否已被使用?,python,scroll,height,pyqt4,mousewheel,Python,Scroll,Height,Pyqt4,Mousewheel,我想在PyQT中找出如何设置鼠标滚轮事件? 我需要它,以便我可以将其连接到Qscroll区域 我使用的代码运行良好。但是尺寸是硬编码的。我需要它根据滚轮(鼠标上)的使用方式进行动态调整。。就像我把鼠标滚轮向上滑动一样。我的帧的高度扩展(如每刻度50像素),反之亦然 self.scrollArea = QtGui.QScrollArea() #set the parent of scrollArea on the frame object of the computers

我想在PyQT中找出如何设置鼠标滚轮事件? 我需要它,以便我可以将其连接到Qscroll区域

我使用的代码运行良好。但是尺寸是硬编码的。我需要它根据滚轮(鼠标上)的使用方式进行动态调整。。就像我把鼠标滚轮向上滑动一样。我的帧的高度扩展(如每刻度50像素),反之亦然

    self.scrollArea = QtGui.QScrollArea()
    #set the parent of scrollArea on the frame object of the computers
    self.scrollArea.setWidget(self.ui.Main_Body)
    self.scrollArea.setWidgetResizable(True)

    #add the verticalLayout a object on PYQT Designer (vlayout is the name)
    #drag the frame object of the computers inside the verticalLayout
    #adjust the size of the verticalLayout inside the size of the  frame

    #add the scrollArea sa verticalLayout
    self.ui.verticalLayout.addWidget(self.scrollArea)
    self.ui.Main_Body.setMinimumSize(400, 14000)
最后一部分是我想加强的地方。我不希望它被硬编码成14000值。 感谢所有愿意帮忙的人。我希望给出的示例代码也能帮助其他需要帮助的人


)我可能对你的问题有点困惑,但下面是一个如何访问调整窗口大小的控制盘事件的示例。如果你使用的是QScrollArea,我不知道你为什么要这么做

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

如果查看文档,您将看到继承自
QWidget
类的一行,该类具有名为
wheeleevent
的函数。您可以将其放入并覆盖继承的函数。

您好,谢谢您的回复。我想发生的是。。我的窗户里有一个框架。这个框架就是我想要调整的那个。取决于鼠标滚轮的使用。这一切都只是设计的东西(我的老师在我的项目中的要求=)谢谢我在修改代码后马上给你反馈再次感谢杰夫!