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. Detecting when a QGraphicsItem's boundingRect has changed
Forum Updated to NodeBB v4.3 + New Features

Detecting when a QGraphicsItem's boundingRect has changed

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 6.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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I am looking for a clean way to detect when the boundingRect of a QGraphicsItem subclass has changed, or is about to change.

    What I have found so far:

    -) prepareGeometryChange is not virtual, therefore I should not subclass it (why, oh why is that one not virtual!?)
    -) The itemChange event has everything BUT the boundingRect. I could track a change in position, but if only the size changes, I wouldn't get an event, according to the docs

    Other ideas?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MaQzma
      wrote on last edited by
      #2

      You are the only one that change the boundingRect (calling prepareGeometryChange), so after you call prepareGeometryChange you could call an other function that does all what you want.

      Mario.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        For a QGraphicsTextItem, I doubt that. It automatically seems to enlarge depending on how much text you put into it.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Hmmm... I would have expected that

          setting the QGraphicsItem::ItemSendsGeometryChanges flag on your graphics item, and

          reimplement the itemChange() method of your QGraphicsItem

          would do the trick, but it seems there is no QGraphicsItem::ItemSizeHasChanged value available. Weird... Good question!

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MaQzma
            wrote on last edited by
            #5

            If your item is a QGraphicsTextItem, its easy; every QGraphicsTextItem have a QTextDocument, so you can connect the signal "contentsChanged()":http://doc.qt.nokia.com/4.7-snapshot/qtextdocument.html#contentsChanged with a slot that do what you want.

            @
            QObject::connect(QGraphicsTextItem::document(), SIGNAL(contentsChanged()),
            this, SLOT(doSomething()));
            @

            [quote author="Asperamanca" date="1341213416"]For a QGraphicsTextItem, I doubt that. It automatically seems to enlarge depending on how much text you put into it.
            [/quote]

            Mario.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Note that, while that may serve the purpose of the TS, it is not a real solution. A new text might have the same size, after all.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MaQzma
                wrote on last edited by
                #7

                Mmm I dont understand what TS mean. We want to detect when boundingRect has changed does not matter if the boundingRect has the same size. Or yes?

                Mario.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #8

                  @Mario: Thanks for the hint regarding QGraphicsTextItem. It might be a useful workaround, if nothing comes up that works for all QGraphicsItem subclasses.

                  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