PDA

View Full Version : QGraphicsItem selection rectangle



ithinkso
27th April 2012, 00:47
Hi,
I have some strange problems, can't figure out why when my QGraphicsItem got selection there's no selection rectangle (this dashed rectangle). Is there any way to turn it on after item get selection and off when lose selection? Or i have to draw this rectangle by my own in some paint event or sth?
Other question, i didn't find any class or built-in solution to resize QGraphicsItem with black dot in the corners of selection rectangle, what is the best way to do it?

ithinkso

sedi
27th April 2012, 02:39
As for the first question, it might be helpful to set the itemIsSelectable/itemIsFocusable flags (http://qt-project.org/doc/qt-4.8/qgraphicsitem.html#GraphicsItemFlag-enum), although I know neither if it is set by default, nor exactly if it will do the trick. If not, style sheets (http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html) might be an option. Just random thoughts.
As for the latter, the funcionality to manually resize QGraphicsItems is afaik not built in, so you'll have to subclass it and build this behaviour by yourself.
As I am a beginner, too, I might get proven wrong by the experts here, especially concerning the first question. I'm pretty sure about the second, though.

ithinkso
27th April 2012, 10:26
it might be helpful to set the itemIsSelectable/itemIsFocusable flags
Forgot to write that, i already set this flag. Items got selection (isSelected() returning true) but the problem is selection rectangle didn't appear


Edit:
I kinda solved this but im not sure it is good way. In paint method i added something like "if(this->isSelected()) {/*code*/}" and drawing selectin rectangle by my own, its seems works fine, what you think? However, Im still wondering why that automatic selection rect didnt work.