PDA

View Full Version : Change color of non selected items in QGraphicsScene/View



s7
7th August 2012, 10:09
I have an application using QGraphicsScene and QGraphicsItem and I can change the color of the selected/mouse-over items using QStyle::StateFlag-enum -let's say selected items turn to color Red-. What I would like to do is also change the color of items that have not been selected to some other color -let's say blue-. What would be the best way to do this? I thought of looking-up the selected items of the scene in the mouse release event -either via ctrl+click,click or rubber band select- and change color of all the items that are not in the selectedItems container of QGraphicsScene but I'm not exactly sure if it is the best way to do it. -By the way, when the scene is first drawn, the items should have their own colors and only turn to blue when a selection event is fired instead of being drawn blue with default not selected flag.- Thanks.

d_stranz
7th August 2012, 19:05
Connect a slot to the QGraphicsScene::selectionChanged() signal. In the slot, retrieve the QList of selected items QGraphicsScene::selectedItems(). Use that list to change the colors. If you keep a copy of the previous selections (initially empty), then you can change the colors only for the items that are not common to the old and new selection lists for better efficiency.