Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Problem with boundingRect() method

    General and Desktop
    1
    1
    1115
    Loading More Posts
    • 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.
    • I
      issam last edited by

      Hi,

      In a QGraphicsScene instance I want to create a QGraphicsSimpleTextItem (label) as a child item of a
      QGraphicsRectItem (Rectangle). So, I have to set the width and the height of the rectangle (the parent) to the width and the height of the label.

      the boundingRect() of the label class :
      @
      MyLabel::QRectF boundingRect() const
      {
      return QGraphicsSimpleTextItem::boundingRect();
      }
      @

      and in the Rectangle:
      @
      QRectF GraphNode::boundingRect() const
      {
      qreal a = (pen().width())/2;
      return QRectF(-1, -1, label->boundingRect().width()+12, label->boundingRect().height()+12)
      .normalized()
      .adjusted(-a, -a, a, a);
      }
      @

      I created a QTabWidget instance as the central area of the MainWindow. Each tab of the tabwidget contain a GraphicsScene. When I close a tab, the application crash with this error :

      @
      pure virtual method called
      terminate called without an active exception
      Aborted
      @

      The Qt Creator indicate that the problem is in this line:

      @
      return QRectF(-1, -1, label->boundingRect().width()+12, label->boundingRect().height()+12)
      @

      Please, help.

      thanks in advance.

      http://www.iissam.com/

      1 Reply Last reply Reply Quote 0
      • First post
        Last post