View Full Version : Selecting QGraphicsItems

19th September 2010, 15:13
I've turned RubberBand mode on in QGraphicsView containing an assortment of custom QGraphicsItems. When I draw a box around them, my understanding is that the items become selected, but there is no visual change in their appearance. I've set the itemIsSelectable flag on all the items, and added a line that checks isSelected() in the paint routine, but I'm not seeing any difference.

Is there some other setting I have to adjust? I'm somewhat limited on time today and haven't had a chance to explore every possibility, but I don't see anything else in the QGraphicsView/Scene/Item framework that I can do to make this happen.

Basically, the program currently allows users to change the classification of an item through a context menu, and I'd like to extend that ability to include classifying groups of items enclosed by the rubber band box.

19th September 2010, 15:18
I always use
if (option->state & QStyle::State_Selected)
//... in the paint method. Did that work for you?

19th September 2010, 16:18
I'll try it. I'm no longer at the machine where my code resides, so it'll have to wait 'til tomorrow.

I was saying

if (isSelected())
// use a certain color for the outline
// use some other color for the outline

20th September 2010, 12:55
OK, this seems to be working as expected. Not sure why the other approach using isSelected() didn't, but it's time to move on.