PDA

View Full Version : QGraphicsItem and signals



aamer4yu
27th December 2006, 04:10
I have a silly problem...
i just wanted to know what item was selected from the scene. For this I tried using signal from the class(derived from QGraphicsItem) but seems I cannot add signals to the subclass :( I also tried remaking the .pro but of no use.

I would like to know if we can emot signals from a class derived from QGraphicsItem or not ?

I know the other method around for this prob... get the items on mouse press and get the required item ;) , but was just curious for the question above :confused:

wysota
27th December 2006, 09:22
i just wanted to know what item was selected from the scene. For this I tried using signal from the class(derived from QGraphicsItem) but seems I cannot add signals to the subclass :(
You can, just inherit from both QObject and QGraphicsItem and make sure QObject is mentioned first in the inheritance list. And remember about the Q_OBJECT macro.


I would like to know if we can emot signals from a class derived from QGraphicsItem or not ?
Yes, if you also inherit QObject :)


I know the other method around for this prob... get the items on mouse press and get the required item ;) , but was just curious for the question above :confused:

How about just using QGraphicsScene::selectedItems()?

aamer4yu
27th December 2006, 11:06
Thanks...:)


How about just using QGraphicsScene::selectedItems()?
Well I am not selecting the items based on rubberbanding... just need to pick item from mouse press... so i guess items() will also do :cool: isnt it ?

wysota
27th December 2006, 11:19
Well I am not selecting the items based on rubberbanding... just need to pick item from mouse press... so i guess items() will also do :cool: isnt it ?

Yes, but is it worth it? I'd simply make items selectable using QGraphicsItem::ItemIsSelectable and then query for items selected - you'll get a much shorter list resulting in a faster application. But maybe you can simply use QGraphicsItem::mousePressEvent() and handle the interaction there? It would be best this way... There is no need to call either items(), selectedItems() nor a mouse press from the scene then.