PDA

View Full Version : QTreeView - how to force an end to a user edit



onamatic
17th November 2008, 13:08
QT4 - X11

I have a QTreeView set up to enable user editing of items. Very simple - double click an item's text and type the changes, <return> ends the edit and commits the change to the model - works a treat.

If an edit is in progress and the user saves the file without hitting return first (and thus not exiting the editor), the changes are not written to disk ( they're not lost - they're still visible in the editor).

I had thought that when the editor lost focus as the user hit the save button, it would end the editing session automatically, but no.

Any suggestions as to how to force the editor to close and commit changes before saving the file please?

wysota
17th November 2008, 14:05
Under unix the keyboard focus and mouse focus are separate. If you want to force the editor to close, use the item delegate that handles it - there are closeEditor() and commitData() methods there.

onamatic
17th November 2008, 22:21
Thanks for that info. wysota. You've fixed my problem instantly.

I didn't realise mouse and keyboard focus were different things; Inow explicitly shift the focus to another widget before saving the file. That causes the editor to exit and commit data without me having to learn about item delegates. I'm all for an easy life!