PyQt 图形视图调整大小事件

发布于 2024-10-26 22:14:53 字数 435 浏览 0 评论 0原文

我想使用 PyQt 将图形视图上的调整大小事件连接到函数。我使用 QtCreator 将 QGraphicsView 添加到 GUI。我尝试了一些变体但没有成功:

gv.pyqtConfigure(resize=self.printR)

QtCore.QObject.connect(gv,QtCore.SIGNAL("resized()"),self.printR)          

gv.resize.connect(self.printR)              

但是上述方法都不起作用(我尝试使用事件名称的许多变体)。

这样做的正确方法是什么?

作为一个扩展问题,是否存在 Qt 中不同小部件可用的所有信号的明确列表,即可以传递给 SIGNAL() 的所有可能值,或小部件可用的“信号”属性(例如,按钮)。单击.connect())?

I would like to connect a resize event on a graphics view to a function using PyQt. I added the QGraphicsView to the GUI using QtCreator. I have tried a few variations without success:

gv.pyqtConfigure(resize=self.printR)

QtCore.QObject.connect(gv,QtCore.SIGNAL("resized()"),self.printR)          

gv.resize.connect(self.printR)              

However none of the above work (I have tried using many variations of the event name).

What is the correct way of doing this?

As an expanded question, is there a definitive list anywhere of all the signals available to different widgets in Qt, i.e. all the possible values that could be passed to SIGNAL(), or the "signal" attributes available to a widget (e.g. button.clicked.connect())?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×眷恋的温暖 2024-11-02 22:14:54

PyQt 类参考 是最好的查找位置对于信号和类方法。

连接简单的信号可以这样完成:

self.connect(senderObject, QtCore.SIGNAL("signalName()"), self.slotMethod)

但是,据我所知,大多数小部件在调整大小时通常不会发出信号。为此,您需要重新实现 QGraphicsView 类及其 resizeEvent 方法,修改它以发出这样的信号,如下所示:

from PyQt4.QtGui import QGraphicsView
from PyQt4.QtCore import SIGNAL

class customGraphicsView(QGraphicsView):

    def __init__(self, parent=None):
        QGraphicsView.__init__(self, parent)

    def resizeEvent(self, evt=None):
        self.emit(SIGNAL("resize()"))

使用 Qt Designer,您应该能够将现有的 QGraphicsView 小部件转换为占位符通过右键单击此类自定义小部件并选择升级到...。如需帮助,请查看此处

我希望这足以回答您的问题。

The PyQt class reference is the best place to look for signals and class methods.

Connecting simple signals can be done like this:

self.connect(senderObject, QtCore.SIGNAL("signalName()"), self.slotMethod)

As far as I can tell, however, most widgets do not normally emit a signal when they are resized. In order to do this, you would need to re-implement the QGraphicsView class and its resizeEvent method, modifying it to emit such a signal, like so:

from PyQt4.QtGui import QGraphicsView
from PyQt4.QtCore import SIGNAL

class customGraphicsView(QGraphicsView):

    def __init__(self, parent=None):
        QGraphicsView.__init__(self, parent)

    def resizeEvent(self, evt=None):
        self.emit(SIGNAL("resize()"))

Using Qt Designer, you should be able to turn your existing QGraphicsView widget into a placeholder for such a custom widget by right-clicking on it and selecting Promote to.... For help, look here.

I hope this sufficiently answers your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文