开发者

PyQt graphicsview resize event

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 no开发者_StackOverflow社区ne 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())?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜