QGraphicsRectItem moves out of the scene
-
I have an Image Viewer, where I draw QGraphicsRectItem. The problem is the QGraphicsRectItem moves out of the scene. How can I fix the items within the sceneRect?
I add the rect items.
I moved the item left and it went out
This completely got scrambled as I resized the viewer, ie, QGraphicsViewer
resizeEvent has been overridden by as below,
QTransform matrix(1, 0, 0, 0, 1, 0, 0, 0, 1); matrix.scale(width() / sceneRect().width(), height() / sceneRect().height()); setTransform(matrix);
What could be the solution?
-
@sayan275 said in QGraphicsRectItem moves out of the scene:
What could be the solution?
The docs contain exactly what you are looking for
-
@raven-worx Thanks for your quick suggestion. It's exactly what I'm looking for.
Only problem is the Image Viewer(with qGraphicsScene and qgrpahicsview) is a plugin, and the Box(QGraphicsRectItem) is another plugin. Now I have to figure out way to getQRectF rect = scene()->sceneRect();
without adding much dependency between the 2 plugins. Hopefully signal-slots does that.
-
@sayan275
why is that a problem?
When you have the item you also have the corresponding scene?!
QGraphicsItem::scene() -
@raven-worx Thanks!! I got it after searching.
But why this event is not responding, when we update the position of the rectItem by keyPress events? -
@sayan275 said in QGraphicsRectItem moves out of the scene:
But why this event is not responding, when we update the position of the rectItem by keyPress events?
what event? Do you mean
QGraphicsItem::itemChange()
?
This change notifier is called in all cases whenever the position changes - it doesn't matter how it is changed.But it might be that you are not changing the position of the item directly?
What i am talking about is, maybe you are just updating the rect's position (top-left corner) and let the item itself always on the position (0,0)?
But long story short, show the code you are using to change the position of your rect item.