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. [Solved] QGraphicsItem::ItemFlagsHaveChanged: correct cast?

[Solved] QGraphicsItem::ItemFlagsHaveChanged: correct cast?

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

    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
    0
    • A Offline
      A Offline
      akonradwesolutions
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        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
        0

        • Login

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