Important: Please read the Qt Code of Conduct -

[SOLVED] How to save data (e.g a path of an image) in a listwidget item?

  • we have a listwidget, and you add an image.. what i did until now was to save the path of the image as statustip withouth having statusbar, so when i needed the path i just called ui->listwidget->item(1)->statustip..

    but this seems just wrong, is there anything for that purpose.. the path must not be visible to user at any time...

  • Use data and setData with custom roles. You might need to subclass QListWidgetItem to store that additional data.

  • Thanks andrew.. so if i want to have a text that i don't want the user to see i should use
    setData(11,text here)?

    i mean role 11 is the correct one for a text?

    works for me just don't know if it is the correct one..

  • *bump Anyone.. Is the role 11 the correct one?

  • I'm not sure about the use of Qt::AccessibleTextRole (11) for this purpose. You can also define your own Role for this. See "ItemDataRole documentation":

    bq. Qt::UserRole 32 The first role that can be used for application-specific purposes.

    bq. For user roles, it is up to the developer to decide which types to use and ensure that components use the correct types when accessing and setting data.

  • Moderators

    No, you should use 32 or greater value. 11 is reserved for accessibility.

  • [quote author="sierdzio" date="1347267425"]No, you should use 32 or greater value. 11 is reserved for accessibility.[/quote]

    Thank you!

Log in to reply