November 7, 2011

maherali maherali
Lab Rat
38 posts

QListWidgetItem

 

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

 Signature 

life is just lines of code

2 replies

November 7, 2011

alexisdm alexisdm
Ant Farmer
123 posts

That’s what the roles are for.

  1. // To avoid magic values:
  2. const Qt::ItemDataRole IdRole = Qt::ItemDataRole(Qt::UserRole + 1);
  3.  
  4. yourItem->setData(IdRole, "some text");
  5. ...
  6. QString id = yourItem->data(IdRole).toString();

November 7, 2011

maherali maherali
Lab Rat
38 posts

Oh thank you very simple.

Regards

 Signature 

life is just lines of code

 
  ‹‹ Best Reporting Tool      [SOLVED] showing a window while a user is editing a QLineEdit field ››

You must log in to post a reply. Not a member yet? Register here!