Is that possible access default QLineEdit used in QListWidget::editItem() ?



  • I have very simple case where I use QListWidget. But I need validate entered strings in some manner. If they are not Ok - then editing must continue. I understand that I can turn to model/view and implement my own ItemDelegate. Then I have create another QLineEdit and setValidator() for it. But this looks too complicated for this simple thing where text just needed to be checked. And there is already code for QLineEdit in QListWidget. Is that possible get pointer to this editor? I would just setValidate there and so on...

    Later I'll need different validation in some different QListWidget-s. I will have to create ItemDelegate with specific QlineEdit for each of them. Or engineer some class which will recognize where it is used and set different validators. But I would rather just set validator for existing editor in each list widget... Code less - create more...



  • How are you adding the items to the QListWidget?



  • Creating one delegate will be less code than setting the validator each time you need it... I'm sure there are tricks possible to get access to the QLineEdit, but I don't think that that is the way to go. Instead, you should either create a [[Doc:QStyledItemDelegate]] that creates the editor directly, or create a new [[Doc:QItemEditorFactory]] and register the type you wish to override. There is an example on that in the docs.



  • bq. How are you adding the items to the QListWidget?

    just addItem()

    bq. Creating one delegate will be less code than setting the validator each time you need it…

    what?? create proper IetmDelegate subclass (with proper methods and signals) and create QLineEdit subclass - this is shorter than just get one pointer (this should be 1-3 lines of code) and then call setValidator() ???


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.