Re: QItemDelegate signals
You can change model directly from within the dialog. Then there is no need for any special treatment and the delegate is not needed here at all, you can do that all from within the view (or any other object) itself.
Re: QItemDelegate signals
Quote:
Originally Posted by
wysota
You can change model directly from within the dialog.
Agreed. But in the case where I use a QLineEdit, the QLineEdit doesn't know anything about my model (or does it?), so how does it communicate to the delegate that it has new data for the model?
-Mic
Re: QItemDelegate signals
When you click on another cell, the editor gets closed and just before that the delegate's setModelData method gets called. When you use an external dialog, you can't do it the same way.
Re: QItemDelegate signals
Ok, lets forget about using a custom dialog as the editor for now. In the specific case of using a QLineEdit as the editor created by the delegate, when you press return, the editor closes and the model data gets updated. You don't have to wait for the user to select another item. Who is responsible for calling the delegate's setModelData method? It wouldn't be the QLineEdit since it should be generic, correct? Secondly, what is the mechanism that calls the setModelData method?
I can image a scenario whereby the delegate base class is connected to some signal that the editor emits when it closes and the delegate in turn calls the setModelData method. Is that how it works?
If so, then perhaps my custom dialog isn't emitting that signal when it closes.
Re: QItemDelegate signals
Quote:
Originally Posted by
Micawber
In the specific case of using a QLineEdit as the editor created by the delegate, when you press return, the editor closes and the model data gets updated. You don't have to wait for the user to select another item.
The spinbox has an event filter installed (at least afair) so that when you press return the delegate gets notified and emits commitData() so that the view can react.
Quote:
Who is responsible for calling the delegate's setModelData method?
The view.
Quote:
I can image a scenario whereby the delegate base class is connected to some signal that the editor emits when it closes and the delegate in turn calls the setModelData method. Is that how it works?
Yes, more or less.
Quote:
If so, then perhaps my custom dialog isn't emitting that signal when it closes.
It surely isn't :) You might connect its accepted() signal to a custom slot in the delegate that will emit commitData().
Re: QItemDelegate signals
Thank you wysota for taking so much time with me. I seem to be quite hamfisted when it comes to understanding these complex interactions.
Quote:
Originally Posted by
wysota
The spinbox has an event filter installed (at least afair) so that when you press return the delegate gets notified and emits commitData() so that the view can react.
I'm guessing you meant lineEdit above. :-)
How does the lineEdit notify the delegate? Afaict the lineEdit has no knowlege of the delegate.
Quote:
Originally Posted by
wysota
You might connect its accepted() signal to a custom slot in the delegate that will emit commitData().
I tried to code that but the commitData() method requires the QWidget pointer as an argument and I can't figure out how to obtain that from the accepted() signal.
Any ideas?