PDA

View Full Version : QItemDelegate signals



Micawber
22nd May 2008, 13:26
Qt4.3.1

I am using a subclass of QItemDelegate to provide a custom editor for a tree view. When I create a Qt editor such as QLineEdit, etc it works fine. But when I create a custom dialog as the editor, when I close the dialog via the done( 0 ) call, the dialog goes away but my new data doesn't show in the tree. Only when I move off of the currently selected item does it show up.

Does this mean that my setModelData method isn't being called until after I move off of the item in question? If so, what signals should I emit in my dialog to tell the framework that I'm finished and I have new data so that setModelData is called in a timely fashion?

Any insight would be appreciated.

-Mic

wysota
22nd May 2008, 13:39
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.

Micawber
22nd May 2008, 13:47
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

wysota
22nd May 2008, 14:32
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.

Micawber
22nd May 2008, 14:55
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.

wysota
22nd May 2008, 16:25
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.


Who is responsible for calling the delegate's setModelData method?
The view.


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.


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().

Micawber
22nd May 2008, 20:29
Thank you wysota for taking so much time with me. I seem to be quite hamfisted when it comes to understanding these complex interactions.


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.



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?