PDA

View Full Version : Selecting QGraphicsItems



SixDegrees
19th September 2010, 16: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.

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

SixDegrees
19th September 2010, 17: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
else
// use some other color for the outline

SixDegrees
20th September 2010, 13: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.

Thanks.