Important: Please read the Qt Code of Conduct -

circle with resize handle.

  • Hi,

    I draw a circle on the QGraphicsScene using QGraphicsPixmapItem.

    #include <QtWidgets>
    class MyGraphicsCircle : public QGraphicsEllipseItem
        MyGraphicsCircle(QGraphicsItem *parent = 0) : QGraphicsEllipseItem(parent)
            setRect(50, 50, 100, 100);
        void mousePressEvent(QGraphicsSceneMouseEvent *event)
            startingPos = event->pos();
        void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
            QRectF currentRect = rect();
            currentRect.setBottomRight(currentRect.bottomRight() + (event->pos() - startingPos));
            startingPos = event->pos();
        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
        QPointF startingPos;
    int main(int argc, char **argv)
        QApplication a(argc, argv);
        QGraphicsView gv;
        QGraphicsScene *gs = new QGraphicsScene(0, 0, 500, 500);
        gs->addItem(new MyGraphicsCircle);;
        return a.exec();

    What I would like to do is the following.

    1. Click the circle. Then the resize handles appear around bounding rect.
    2. Move the cursor to one of handles and press and hold the mouse button.
    3. Drag the cursor. While draggin, the circle grows or shrink.
    4. Release the mouse button. The circle with desired size is drawn.

    Any idea how to achieve this goal?

  • Qt Champions 2017

    In order to achieve this, there is not direct way of doing this. Here is how you can achieve this.

    1. Store the bounding rectangle value in your program.
    2. When the circle is pressed, find out if the point is inside the bounding rectangle
    3. You draw the rectangle around circle in gray colour
    4. Now you start handling the mouse move events
    5. Based on the MouseMove events, you can start redrawing the circle again.

Log in to reply