Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QListWidget: Avoid name duplicates when using the persistent editor



  • When using the persistent editor provided by the QListWidget to modify the text of a QListWidgetItem, what is the best way to make sure that the user does not enter a text that is already taken by another item?

    Retrieving the list of the item names is not my problem but I don't understand what's the best way to check if the currently entered text is unique before it is applied.

    Thank you for your help.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    One way to do it is to create a custom QValidator using your list of name as validation point

    Hope it helps



  • @SGaist Thank you very much for your quick reply.
    Using a QValidator does indeed seem to make sense. However, from reading the documentation of the QListWidget I couldn't figure out how I would apply / submit my custom QValidator class to the persistent editor. Can you give me a quick hint?


  • Lifetime Qt Champion

    The same way you would for a QTableView, have a look at setItemDelegate and it's various incarnations