3

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

aaa90210
  • 11,295
  • 13
  • 51
  • 88
  • If this is still something you are interested in, please see my answer [here](http://stackoverflow.com/a/36630691/2988730). You can do what you want, but it takes some extra Python magic. – Mad Physicist Apr 14 '16 at 18:04

1 Answers1

8

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.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
MadDogX
  • 347
  • 2
  • 8
  • This answers the question to a large extent - it seems that the only way to connect to a resize event is by using a derived class like your example shows. I also did not know about the "Promote to" option, that is useful, thanks =) – aaa90210 Mar 29 '11 at 22:56
  • You do not need to subclass the widget that you are connecting to: http://stackoverflow.com/a/36630691/2988730. – Mad Physicist Apr 14 '16 at 18:06