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. Updating QGraphicsItem when editing text of containing QGraphicsTextItem
Forum Updated to NodeBB v4.3 + New Features

Updating QGraphicsItem when editing text of containing QGraphicsTextItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.2k Views 2 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by ModelTech
    #1

    I am trying to experiment with QGraphicsTextItem that is a child of a QGraphicsItem. The QGraphicsItem draws a rectangle around the QGraphicsTextItem and the idea is that this rectangle resizes with each change to the text of the QGraphicsTextItem. I use the mouseDoubleClicked event on the QGraphicsItem to make the QGraphicsTextItem editable and the focusOutEvent on the QGraphicsItem to make the QGraphicsTextItem no longer editable. The code for that looks as follows (where NameEditor is the QGraphicsTextItem and StateEditor is the QGraphicsItem):

    void StateEditor::focusOutEvent(QFocusEvent *Event) {
        NameEditor->setTextInteractionFlags(Qt::NoTextInteraction);
        QGraphicsItem::focusOutEvent(Event);
    }
    
    void StateEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *Event) {
        if (NameEditor->textInteractionFlags() == Qt::NoTextInteraction)
            NameEditor->setTextInteractionFlags(Qt::TextEditorInteraction);
        QGraphicsItem::mouseDoubleClickEvent(Event);
    }
    

    My question is however: how can I redraw the QGraphicsItem with each modification of the text in the QGraphicsTextItem? In particular, when its boundingbox becomes smaller, the area of the old bounding box should be redrawn as well.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Out of curiosity, why not paint the rectangle directly in your custom QGraphicsTextItem ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by
        #3

        Good point. Didn't think about that. However, I intend to make the QGraphicsItem more complex in the future with a second QGraphicsTextItem... So, for that case I guess I need to do it in the QGraphicsItem. Or can this be done also differently?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Maybe a QGraphicsItemGroup ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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