Custom editor for QListView



  • I have an existing QListView. Currently, double-clicking on a cell allows the user to edit the contents of that cell, and I see the change get committed to the model behind the view.

    I need more control over that edit capability; rather than let the user simply type something, I want to open a widget to make them select a directory, and commit that (as a string) to the model. Making that is no problem; what I can't figure out is how to have the double-clicking action open my selection widget.

    I'm digging around, and I find the function QAbstractItemView::edit that looks like what I want to override? Presumably I will need to create a new class, inheriting from QListView, and override edit in that subclass? Is there another way? I was looking at delegates but I can't work out from the documentation if there is a way to direct a QListView to use something I provide for editing.


  • Lifetime Qt Champion

    Hi,

    You should implement a QStyledItemDelegate, that way you can provide your custom editor.

    Hope it helps



  • I did figure it out in the end, mostly. The QT documentation is a good reference guide but as something to learn from, it's a bit rough. :(


Log in to reply
 

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