Custom delegates, editors, and "chicken or egg" problem
-
According to the documentation, when the editing is finished in a custom editor, there is a signal
closeEditor()
which should be emitted. I would like to change the optional argumentQAbstractItemDelegate::EndEditHint
fromQAbstractItemDelegate::NoHint
toQAbstractItemDelegate::EditNextItem
. This means that my custom editor widget needs to emit that signal itself (somewhere).Setting up a delegate for editing an item in a table view, if it is something simple like a combo box, seems to work OK without anything special, but looking at the
Spreadsheet Example
, I would need to subclassQComboBox
if I wanted to change the argument as stated above.So the question is this: Where to emit the signal?
If a
QLineEdit
is used, as in the spreadsheet example, there is a custom function which is connected to theeditingFinished
signal which does this (as well as emitting thecommitData
signal). But one of my editors (on a field in a table view) is actually like a dialog which opens an editor containing another table view with its own model, etc. and some buttons (OK, Cancel, etc. although it is not a dialog, but inheritsQFrame
). So I can hook up the buttons'clicked
signal to something like that. Would that be the standard procedure? Or should I emit thecloseEditor
andcommitData
signals somewhere else? (I assume that the frame'scloseEvent
would not be appropriate here ... i.e., this would be the "chicken or egg" part of the question. Emitting thecloseEditor
signal would eventually callclose()
on my editor, and only then would I receive the close event). -
@Robert-Hairgrove said in Custom delegates, editors, and "chicken or egg" problem:
QAbstractItemDelegate::EndEditHint from QAbstractItemDelegate::NoHint to QAbstractItemDelegate::EditNextItem.
Why?
It's not really possible, at least not when looking at the code where it is emitted. EditNextItem is only emitted when the TAB key is pressed. -
@Christian-Ehrlicher Thank you, Christian ... in that case, for most of the delegates there is no need to emit this signal myself.
However, I mentioned a custom dialog-like editor in my last paragraph. I will need to emit the signal here in any case, but I'm not sure which slot or event to use. If I have a slot connected to my "OK" button's
clicked
signal, would that be the most appropriate for emittingcloseEditor
? -
I think this is now solved ... I can follow the example of "Star Delegate" almost verbatim.