質問

I have the qmainwindow which homes several qgraphicsitems(an inherited class from qgraphicsitems) within a qgraphicsview. These items contains their personal items which are inherited from qgraphicsitems also. These items listen to mouse press events. These items also have their own other data properties such as custom id.

I can pass mouse events from these items to the main window. I need to pass the above said custom id of the clicked item to the main window also with the event, so that main window can change its appearance to suite the clicked item.

What way can i do this ??

役に立ちましたか?

解決

Maybe I didn't get your question, but I would use SLOTS and SIGNALS rather than events. For example, put a signal on the QGraphicsScene, something like:

void myItemClicked(int custom_id);

so, when your items catch mouse event, they could do:

emit scene()->myItemClicked(my_id);

MainWindow could connect that signal coming from the scene to one of its slots and change its properties according to the id of the item coming along the signal.

Otherwise, if you allow items to call methods of the QMainWindow (this is a design choice) yuo could store a pointer to it in the (for example) the scene, so items can do:

scene()->mainwindow->aMethod();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top