Need to help to select the QGraphicsPixmapItem when click on it.
-
Thanks in advance ...... :)
-
it should be enough to call this on your QGraphicsPixmapItem:
@item->setFlag(QGraphicsItem::ItemIsSelectable);@ -
But, I also want to draw rectangle around the image when i click on or select it ...
-
I am attaching the URL of images of my desire result.
The following link is just my normal image on view.
http://www.image-upload.net/di/28SA/33.png
The following link will show my desirable result.
-
then also implement the paint method:
@
void MyGraphicsPixmapItem::paint(QPainter painter, const QStyleOptionGraphicsItem option, QWidget *widget)
{
Q_UNUSED(widget);painter->setRenderHint(QPainter::SmoothPixmapTransform, (d->transformationMode == Qt::SmoothTransformation)); painter->drawPixmap(this->offset(), this->pixmap()); if (option->state & QStyle::State_Selected) { //draw your selection frame }
}
@But since it seems that you also want interaction with the graphicsitem it would be better to introduce a subclassed QGraphicsItemGroup and do your painting and interaction there. Because you would also have to update the bounding rect of the pixmap item once it is selected, etc. ...
-
Ok....
Can i do same task for QGraphicsPathItem or whatever i draw on View using this method ?
-
as long as you stay generic to QGraphicsItem ... why not.
-
paint method is not calling ..... :(
-
sry.... i forgot to addItem in the scene. :P
-
But when i click on or select the image, it does not show its Selected State(i.e. QStyle::State_Selected) .