Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 593
aaa90210 Avatar asked Apr 11 '26 02:04

aaa90210


1 Answers

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.

like image 59
MadDogX Avatar answered Apr 14 '26 07:04

MadDogX