PDA

View Full Version : List View with renamable items?



MattT
16th July 2010, 12:58
I'm trying to figure out how to create a list view (either a plain QListView or a QListViewWidget, I suppose) which allowss the user to edit the item names.

For example, the list has three items, the user double-clicks (or, more appropriately, clicks twice) on an item and the text for that item turns into a text box, which the user can then edit. When the user presses enter or changes focus from the box, the text box turns back into plain text with the new name.

Ideally, when we first add an item to the list, it will start out in "rename mode" so that the user can give that item a name. So the user clicks the "add [item]" button, a new item appears on the list in "rename mode", they enter in the item's name, hit enter, and then new item finally turns into regular text with the user's name.

Google and the forum's search function are of no help here; searching "qlistview rename" doesn't return what I'm looking for. It does look like QT3 supported this more easily, but I'm using 4.6. I'm a QT newbie, though, so I may very well be missing something obvious.

aamer4yu
16th July 2010, 13:14
You need to make the item editable. And Qt will invoke editing on double click or based on edit triggers.

MattT
17th July 2010, 11:21
Awesome, thanks, that was exactly the hint I needed to find what I needed for figuring out what I needed. Knowing to use the keyword "edit" instead of "rename" helped me greatly. I also found the edit() function of QAbstractItemClass to get the second part of my question working.