Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    [Solved] QGraphicsItem::ItemFlagsHaveChanged: correct cast?

    General and Desktop
    2
    3
    1232
    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.
    • A
      Asperamanca last edited by

      I would like to use the QVariant value from QGraphicsItem::itemChange with the change flag QGraphicsItem::ItemFlagsHaveChanged.

      The docs say about this change:
      bq. The item's flags have changed. The value argument is the new flags (i.e., a quint32). Do not call setFlags() in itemChange() as this notification is delivered. The return value is ignored.

      From this, I gather the correct cast from value to QGraphicsItem::GraphicsItemFlags is:

      @static_castQGraphicsItem::GraphicsItemFlags(value.value<qint32>())@

      However, this feels wrong. What if I compile with 64 bits? Won't the Flags be 64 bits wide by default then? Okay, the cast would still work, but it doesn't feel right?

      IS it right?

      1 Reply Last reply Reply Quote 0
      • A
        akonradwesolutions last edited by

        The meta type stored by the QVariant in this case is QVariant::Uint, so the correct cast would be:

        @value.value<uint>()@

        Since the notification tells you that the flags have already changed you don't actually need this cast. Just use QGraphicsItem::flags() to get the current value.

        1 Reply Last reply Reply Quote 0
        • A
          Asperamanca last edited by

          Thanks to your post, I realized I should simply look in the code. And there it is:

          qgraphicsitem.cpp
          @ // Notify change.
          itemChange(ItemFlagsHaveChanged, quint32(flags));@

          I guess you get QVariant::Uint for qint32 when using 32-bit Qt. Might be different for 64 bits. So it seems my original cast was correct.

          Side note: I forward the value into a class that doesn't have access to flags(). So the cast is relevant for me.

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