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. QListWidgetItem
Qt 6.11 is out! See what's new in the release blog

QListWidgetItem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.7k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

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

        Oh thank you very simple.

        Regards

        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