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. QGraphicsRectItem boundingRect() not updating with mousemove event
QtWS25 Last Chance

QGraphicsRectItem boundingRect() not updating with mousemove event

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsitemboundingrectmousemove
2 Posts 2 Posters 768 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
    sayan275
    wrote on 3 Sept 2020, 03:17 last edited by
    #1

    I have a QgraphicsRectItem, with a overridden boundingRect().
    I try to print the boundingRect(), in ItemChange() with ItemPositionChange flag, but it doesn't update.

    TiltBoxItem::itemChange QPointF(-485.063,4.53229)
    TiltBoxItem::itemChange boundingRect:: QRectF(728.313,289.567 166.75x90.135)
    TiltBoxItem::itemChange m_BOX:: QRectF(728.813,290.067 165.75x89.135)
    TiltBoxItem::mouseMoveEvent m_BOX:: QRectF(728.813,290.067 165.75x89.135)
    

    the value which shows for boundingRect and m_box is same as I drawn on scene. After that I have moved it throughout the scene, but the bounding box/m-box is not updated.

    the code is like this

    QRectF TiltBoxItem::boundingRect() const
    {
        return QGraphicsRectItem::boundingRect();
    }
    
    QVariant TiltBoxItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
    {
        if(change == QGraphicsItem::ItemPositionChange)
        {
            qInfo()<<__FUNCTION__<<value.toPointF();
            qInfo()<<__FUNCTION__<<"boundingRect::"<<boundingRect();
            qInfo()<<__FUNCTION__<<"m_BOX::"<<m_box;
        }
        return QGraphicsItem::itemChange(change, value);
    }
    
    void TiltBoxItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    {    
        QGraphicsItem::mouseMoveEvent(event);
        update();
        qInfo()<<__FUNCTION__<<"m_BOX::"<<m_box;
    }
    

    m_box is

     QRectF m_box;
    
    //and in ctor we initialize it
    m_box = rect;
    setRect(m_box);
    

    Why the boundingRect is not updating with the mousemoveEvent?...is there some code required to update the boundingRect ?

    Any help is appreciated.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eyllanesc
      wrote on 3 Sept 2020, 06:30 last edited by eyllanesc 9 Mar 2020, 06:32
      #2

      boundingRect does not depend on the position of the item with respect to the scene since it is in coordinates with respect to the item. I recommend you review https://doc.qt.io/qt-5/graphicsview.html so that you understand the different coordinate systems that are handled.

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      1

      2/2

      3 Sept 2020, 06:30

      • Login

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