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. How to identify boundingbox size changes in QGraphicsTextItem ?
Qt 6.11 is out! See what's new in the release blog

How to identify boundingbox size changes in QGraphicsTextItem ?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 854 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
    Sridharan
    wrote on last edited by
    #1

    While editing the content of QGraphicsTextItem, bounding box size changes. I need to perform some action , if bounding box size changes. I don't find any signal available in QGraphicsTextItem which gets emitted on bounding box change. Is there any other way to get update on boundingbox size changes ?

    JonBJ 1 Reply Last reply
    0
    • jsulmJ jsulm

      @Sridharan Of course you do not get compiler error!
      That's why I said that you should switch to Qt5 connect syntax!

      Again, do you see the issue here: connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged)); ?

      S Offline
      S Offline
      Sridharan
      wrote on last edited by Sridharan
      #8

      @jsulm
      [solved]

      Thanks. I have corrected it to,

      QGraphicsTextItem* textItem = new QGraphicsTextItem("New user");
      textItem->setFlag(QGraphicsItem::ItemIsMovable);
      textItem->setFlag(QGraphicsItem::ItemIsSelectable);
      textItem->setTextInteractionFlags(Qt::TextEditorInteraction);

      connect(textItem->document(), &QTextDocument::contentsChanged, this, &MainWindow::textcontentsChanged);

      It's working now.

      1 Reply Last reply
      1
      • S Sridharan

        While editing the content of QGraphicsTextItem, bounding box size changes. I need to perform some action , if bounding box size changes. I don't find any signal available in QGraphicsTextItem which gets emitted on bounding box change. Is there any other way to get update on boundingbox size changes ?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @Sridharan
        Since I see various ...Changed() signals for e.g. position change but not size change, I can only think: save the item/bounding box size before the editing, compare it after the editing, emit your own signal if they are different?

        See also Detecting when a QGraphicsItem's boundingRect has changed or QGraphicsItem::itemChange notified for position change but not for size change, but I don't think they tell anything different.

        S 1 Reply Last reply
        0
        • JonBJ JonB

          @Sridharan
          Since I see various ...Changed() signals for e.g. position change but not size change, I can only think: save the item/bounding box size before the editing, compare it after the editing, emit your own signal if they are different?

          See also Detecting when a QGraphicsItem's boundingRect has changed or QGraphicsItem::itemChange notified for position change but not for size change, but I don't think they tell anything different.

          S Offline
          S Offline
          Sridharan
          wrote on last edited by Sridharan
          #3

          @JonB

          I have tried idea provided in your 1st link, connect contentsChanged() signal to my own slot ( textcontentsChanged ) . By my slot is not getting executed. Attached my code below, anything wrong here ?

          QGraphicsTextItem* textItem = new QGraphicsTextItem("New user");
          textItem->setFlag(QGraphicsItem::ItemIsMovable);
          textItem->setFlag(QGraphicsItem::ItemIsSelectable);
          textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
          
          QTextDocument* document = textItem->document();
          connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged));
          
          jsulmJ 1 Reply Last reply
          0
          • S Sridharan

            @JonB

            I have tried idea provided in your 1st link, connect contentsChanged() signal to my own slot ( textcontentsChanged ) . By my slot is not getting executed. Attached my code below, anything wrong here ?

            QGraphicsTextItem* textItem = new QGraphicsTextItem("New user");
            textItem->setFlag(QGraphicsItem::ItemIsMovable);
            textItem->setFlag(QGraphicsItem::ItemIsSelectable);
            textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
            
            QTextDocument* document = textItem->document();
            connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged));
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Sridharan said in How to identify boundingbox size changes in QGraphicsTextItem ?:

            connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged));

            Do you see what is wrong here?
            You should use Qt5 connect syntax to get compiler errors if your connect statement is wrong.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            1
            • jsulmJ jsulm

              @Sridharan said in How to identify boundingbox size changes in QGraphicsTextItem ?:

              connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged));

              Do you see what is wrong here?
              You should use Qt5 connect syntax to get compiler errors if your connect statement is wrong.

              S Offline
              S Offline
              Sridharan
              wrote on last edited by Sridharan
              #5

              @jsulm
              No compilation error. Problem is my slot function is not executed when i modify text

              jsulmJ JonBJ 2 Replies Last reply
              0
              • S Sridharan

                @jsulm
                No compilation error. Problem is my slot function is not executed when i modify text

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Sridharan Of course you do not get compiler error!
                That's why I said that you should switch to Qt5 connect syntax!

                Again, do you see the issue here: connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged)); ?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply
                0
                • S Sridharan

                  @jsulm
                  No compilation error. Problem is my slot function is not executed when i modify text

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #7

                  @Sridharan
                  As @jsulm says. Which is why you should switch to https://wiki.qt.io/New_Signal_Slot_Syntax. It's not even "new" now, the syntax you are using is like a decade old, and is the cause of exactly this kind of error, which we have to keep pointing out to people when they get it wrong over and over....

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Sridharan Of course you do not get compiler error!
                    That's why I said that you should switch to Qt5 connect syntax!

                    Again, do you see the issue here: connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged)); ?

                    S Offline
                    S Offline
                    Sridharan
                    wrote on last edited by Sridharan
                    #8

                    @jsulm
                    [solved]

                    Thanks. I have corrected it to,

                    QGraphicsTextItem* textItem = new QGraphicsTextItem("New user");
                    textItem->setFlag(QGraphicsItem::ItemIsMovable);
                    textItem->setFlag(QGraphicsItem::ItemIsSelectable);
                    textItem->setTextInteractionFlags(Qt::TextEditorInteraction);

                    connect(textItem->document(), &QTextDocument::contentsChanged, this, &MainWindow::textcontentsChanged);

                    It's working now.

                    1 Reply Last reply
                    1

                    • Login

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