PDA

View Full Version : QGraphicsSvgItem - how to make clickable?



scott.deagan
8th March 2012, 10:35
How can I make a QGraphicsSvgItem that is added to a scene clickable? I am adding it as follows:



svgItem = new QGraphicsSvgItem(":/MySVGImage.svg");
svgItem->scale(0.1, 0.1);
scene->addItem(svgItem);
...
ui->graphicsView->setScene(scene);


How can I now detect that this particular svgItem has been clicked?

Any help really appreciated. Thanks.

wayfaerer
8th March 2012, 17:05
How do you want to handle the clicks?

If it's just basic stuff like selecting or moving it around, you can just set flags (e.g., "setFlag(ItemIsSelectable,true);"). If it's more complicated, you should subclass QGraphicsItem or QGraphicsSvgItem and implement your own functionality. You'd need to reimplement QGraphicsItem::mousePressEvent.

I recommend looking at this video: http://www.youtube.com/watch?v=hgDd2QspuDg