Question

I am creating a circuit schematic editor using Qt Creator. I have a QGraphicsScene/QGraphicsView canvas that I would like to drop images of circuit components onto and move them around.

I am currently using a pixmap QGraphicsItem and adding it to the canvas and making it movable. This works great when you click directly on the symbol's lines, however the symbol does not move when the transparent areas in the image are clicked.

Is there a way to expand the hitbox/mouse area to make these transparent regions respond the same as the other regions do on the symbol? Below is how I am adding the image. (I need the image transparent so that other symbols are visible behind/infront of it)

QGraphicsItem* b = canvas.addPixmap(QPixmap(":/images/ground2.gif"));
b->setFlag(QGraphicsItem::ItemIsMovable);
b->setPos(qrand()%int(canvas.width()),qrand()%int(canvas.height()));

All help is much appreciated! Thanks! Josh

Was it helpful?

Solution

You can call QGraphicsPixmapItem::setShapeMode( QGraphicsPixmapItem::BoundingRectShape ) to have the item treated a rectangle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top