Setting boundingRect() for a custom QGraphicsObject drawn using mouse
Unsolved
General and Desktop
-
I want to draw a custom rectangle when dragged using a mouse events. Since i need additional features like resizing the rectangle,
contextMenuEvents()
and other stuff, i subclassedQGraphicsObject
and overriden pure virtual functions. Moreover, i have a subclassedQGraphicsScene
which handles mouse events.What do i want:
To be able to draw custom rectangle when mouse events are triggered on
QGraphicsScene
. Like left mouse button->drag.
Drawing it simply usingQGraphicsRectItem
works fine.Problem:
How to set
boundingRect()
of my custom rectangle andpaint()
or update the rectangle as the mouse moves on theQGraphicsScene
?Currently, i have an empty subclassed
RectItem
. Which looks like this:RectItem::RectItem(QObject* parent) : QGraphicsObject() { } QRectF RectItem::boundingRect() const { // how to set bounding rect when rectangle is drawn dynamically using mouse? } void RectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { // how to update paint() and show a rectangle to the user? }
How to implement both
boundingRect()
andpaint()
?