• Hi
    I have a simple question, sometimes in QListWidget I need to display an item with hidden tag like the ID for further operations like deleting the item from the database.

    Is there a field that can be assigned with the display text just as hidden field, it would be great for simple scenarios.
    The same feature exists in .NET as tag field as I remember.


  • That's what the roles are for.
    @// To avoid magic values:
    const Qt::ItemDataRole IdRole = Qt::ItemDataRole(Qt::UserRole + 1);

    yourItem->setData(IdRole, "some text");
    QString id = yourItem->data(IdRole).toString();

  • Oh thank you very simple.


Log in to reply

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