Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. circle with resize handle.

circle with resize handle.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 983 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samdol
    wrote on last edited by
    #1

    Hi,

    I draw a circle on the QGraphicsScene using QGraphicsPixmapItem.

    #include <QtWidgets>
    class MyGraphicsCircle : public QGraphicsEllipseItem
    {
    public:
        MyGraphicsCircle(QGraphicsItem *parent = 0) : QGraphicsEllipseItem(parent)
        {
            setRect(50, 50, 100, 100);
        }
    protected:
        void mousePressEvent(QGraphicsSceneMouseEvent *event)
        {
            startingPos = event->pos();
            grabMouse();
        }
        void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
        {
            QRectF currentRect = rect();
            currentRect.setBottomRight(currentRect.bottomRight() + (event->pos() - startingPos));
            setRect(currentRect);
            startingPos = event->pos();
            QGraphicsEllipseItem::mouseMoveEvent(event);
        }
        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
        {
            ungrabMouse();
        }
    private:
        QPointF startingPos;
    };
    
    int main(int argc, char **argv)
    {
        QApplication a(argc, argv);
        QGraphicsView gv;
        QGraphicsScene *gs = new QGraphicsScene(0, 0, 500, 500);
        gv.setScene(gs);
        gs->addItem(new MyGraphicsCircle);
        gv.show();
        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?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      5

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved