views:

285

answers:

3

I've done lots of stuff with pygtk however i'm deciding to learn pyqt, im stuck at the qgraphicsview i have absolutley no idea how to get signals from the items i place on the graphics view, primarily mouse events.How do i get the mouse events from idividual items in a scene?

A: 

Right after you create an item, connect the signals you want from it to the instance of the widget that contains it.

shoosh
ive read loads of pages of docs containing 'QGraphicsThis','QGraphicsThat' i'm yet to see any graphics item with any signals listed in its api, moreover graphics items dont appear to have a connect() method. where are these signals located in the api reference? and how can i connect them to my own functions?
spearfire
True, because QGraphicItem doesn't inherit from QObject. in C++ however you can create your own class that inherits from both QObject and QGraphicItem and create an item that emits signals. I'm not sure how this is done in python though.
shoosh
You can either do as shoosh says, inherit QObject and the QGraphicsXxx-class that you're after. (Remember to inherit QObject first and add the Q_OBJECT macro, etc). If you create your own graphics items, simply inherit QGraphicsObject which is a QObject (you still need the Q_OBJECT macro, etc, but no need to inherit QObject again)
e8johan
A: 

Another option is to just give up using signals and have your instance of QGraphicItem directly call a method of its parent by keeping a reference to it. This is less pretty than using signals but ultimately, it gets the job done.

shoosh
+1  A: 

QGraphicsItem is not a QObject and cannot send signals, nor receive slots. Instead, you must handle events. You can do that either through an event filter, sub-classing the view or scene to intercept events or simply sub-classing the items themselves and implementing the event handling functions (see protected member functions in the documentation). Perhaps this example can be of interest: http://doc.trolltech.com/4.6/graphicsview-diagramscene.html .

e8johan