Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    QListWidgetItem

    General and Desktop
    2
    3
    1871
    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.
    • M
      maherali last edited by

      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.

      thanks

      life is just lines of code

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

        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();
        @

        1 Reply Last reply Reply Quote 0
        • M
          maherali last edited by

          Oh thank you very simple.

          Regards

          life is just lines of code

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