QGraphicsItem and signals
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:
Re: QGraphicsItem and signals
Quote:
Originally Posted by
aamer4yu
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.
Quote:
I would like to know if we can emot signals from a class derived from QGraphicsItem or not ?
Yes, if you also inherit QObject :)
Quote:
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()?
Re: QGraphicsItem and signals
Thanks...:)
Quote:
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 ?
Re: QGraphicsItem and signals
Quote:
Originally Posted by
aamer4yu
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.