QListWidget: what signal for "item edition start" event?
-
Hello,
I am successfully using the QListWidget, and also reacting on text changes from the user side (with the itemChanged signal). The problem that I have is following:
The list displays text items like "objectName (objectType)". When the user enters text edit mode for one item, the text should only display "objectName", since the user can only edit the object name part. Once edition is finished, the system will append the object type information to the string.
Under MVS, once would use the OnBeginlabeledit and the OnEndlabeledit handlers.
In Qt, itemChanged is equivalent to OnEndlabeledit. What would be the equivalent of OnBeginlabeledit?Thanks!
-
The easiest way would be, you create a "custom delegate":http://doc.qt.nokia.com/4.7/model-view-programming.html#delegate-classes
The delegate creates the editor, sets tghe values to the editor and also sets it back to the view. So this is the perfect place for those things.
-
You might considder using "QxtListWidget":http://libqxt.bitbucket.org/doc/0.6/qxtlistwidget.html instead of QListWidget. It has signals for these events.
-
Thanks a lot to both of you. The delegate solution works nicely :)
-
To be really really pedantic:
- the "objectName (objectType)" form should be returned by your model as the DisplayRole for that index;
- the "objectName" for the EditRole;
- when you write a new object name, setData is called for the EditRole -- and therefore your model should append the new object name in its internal storage, then return "objectName (objectType1, objectType2)" as the new DisplayRole.