PyQt 图形视图调整大小事件
我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PyQt 类参考 是最好的查找位置对于信号和类方法。
连接简单的信号可以这样完成:
但是,据我所知,大多数小部件在调整大小时通常不会发出信号。为此,您需要重新实现 QGraphicsView 类及其 resizeEvent 方法,修改它以发出这样的信号,如下所示:
使用 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:
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:
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.