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. [solved] How to get the center coordinate of moving circle by mouse?
Forum Updated to NodeBB v4.3 + New Features

[solved] How to get the center coordinate of moving circle by mouse?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.2k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    romeo.rbw
    wrote on last edited by
    #1

    Hi...
    Recently I make a circle using QGraphicsEllipsItem, and it movable by mouse click and drag. The problem is: I cannot detect the center of this circle. I want to detect every coordinate when user move the mouse but it always shows the center of my scene. Very appreciate if there is some help and suggestion. Thank you...
    @
    void HandleItem::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget )
    {
    paint->setPen( m_color );
    paint->setBrush( m_color );

    QRectF rect = boundingRect();
    QVector<QPointF> points;
    QRect frame;
    switch( m_role )
    {
    case CenterHandle:
    paint->drawEllipse( rect );
    frame = paint->window();
    qDebug() << "coordinate center ellips(x,y) : " << frame.center().x()<<" , "
    << frame.center().y();
    break;

    case RightHandle:
    .....
    }
    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Get it from boundingRect() - after all those are the coordinates you are using to draw the ellipse.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        romeo.rbw
        wrote on last edited by
        #3

        I try to get it from boundingRect(), when the item was moved it still detect the same coordinate, but now it always display the coordinate of the item center. How to detect the new center coordinate after it was moved? I appreciate if there is other suggestion, the boundingRect() code:

        @
        QRectF HandleItem::boundingRect() const
        {
        QPointF point = m_item->boundingRect().center();

        switch( m_role )
        {
        case CenterHandle:
        qDebug() << "coordinate of the center (x,y) : " << m_item-> boundingRect().center().x() <<" , " << m_item-> boundingRect().center().y();
        return QRectF( point-QPointF(15, 15), QSize( 30, 30 ) );

        case RightHandle:
        ...
        }

        return QRectF();
        }
        @

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          is sceneBoundingRect() what you are looking for?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • R Offline
            R Offline
            romeo.rbw
            wrote on last edited by
            #5

            Yes...it works using sceneBoundingRect(), thanks sierdzio and raven :)

            1 Reply Last reply
            0

            • Login

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