[Solved] QGraphicsItem::ItemFlagsHaveChanged: correct cast?

  • 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:


    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?

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

    [object Object].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.

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

    @ // 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.