PDA

View Full Version : QItemDelegate and default actions...



TemporalBeing
4th April 2009, 18:43
I have a QTableWidget that uses a custom QItemDelegate derived object to handle cell edits. Also part of the UI are a series of buttons - 4 to move, and 3 to add/edit/remove data. The Add button has the auto-default property, and if I take it off it goes to another button.

I have no problem with the Add button having the auto-default property, and it works well.

My problem is that when a user edits a cell; if they hit 'enter' to accept their changes, it also triggers the default button. So the changes are saved, but the user also gets prompted to add another row of data. (And this can be quite annoying.)

I'd really like it if they could just press enter to accept their changes and it would simply save the data in the delegate editor.

Is there any way I can correct this?

I discovered I can't send signals from within the QItemDelegate class as the functions (createEditor, setEditorData, setModelData) are all const functions. (Otherwise I could just send signals when the editor is created/destroyed to disable/enable the buttons to achieve the desired effect; but I'm not sure that would produce a 100% desired affect either.)

aamer4yu
4th April 2009, 18:45
Have a look at QAbstractItemDelegate::editorEvent and return true for enter pressed.

Hope it might work :)