PDA

View Full Version : [itemview] delegation to a dialog ...



lauranger
24th November 2006, 16:56
Hi
I have data in a tableview and for some column,
I need to edit a cell via a dialog.
Deriving from QItemDelegate and implementing
* createEditor to return a modal dialog
* setEditorData to extract the structured data from the variant and put it on the dialog
* setModelData to take back the structure data from the dialog and put it back in the variant in the model,
I have quite all right *except* that setModelData is not executed straight away after
the dialog disappears. Only when I click back on the tableview... :(

Anybody has an hint on how to do that kind of thing ?
Should I use an intermediate button as a proxy editor in the cell (my user may not like this indirection) ?

Thanks in advance. Regards.

lauranger
24th November 2006, 18:59
I tested the way of the intermediate button,
but I still have to pressed enter or tab or click sideway after dialog quits in order to get
setModelData called :(
What I did :

in createEditor : instanciate a special push button that can carry a QVariant and which clicked() signal is connected to a method of my itemdelegate
in setEditorData : I put the qvariant onto the button
in the slot for clicked(), i setup the dialog with the qvariant, exec the dialog
and on accept i copy dialog qvariant to special button, waiting for setModelData
to keep clean and then emitting commitData and closeEditor
in setModelData I call setData with the qvariant on the special button

The problem is my emit of commitData is vain : my setModelData
is called ony when I as a user interact with the table.

I feel likeI am gonna gruik --pig noise-- by keeping the index in the special button and use it to call setData with :crying:

Anybody a hint ?
It seems that many things require a user interaction to be taken into account : calling reset from my model isi not enough to have my tableview repainted :(

Have a nice week end :).

wysota
24th November 2006, 19:04
Why not call setData directly from the dialog and ignore the rest? You could even do it simpler if you uset setItemWidget on the view when acting upon change of the current item.

lauranger
27th November 2006, 09:20
Hi Wysota

Why not call setData directly from the dialog and ignore the rest? You could even do it simpler if you uset setItemWidget on the view when acting upon change of the current item.
Why not ? This was my last proposition, with the need to keep the index to setData in.
I could not find setItemWidget in QTableView.
Regards.

jpn
27th November 2006, 09:25
I could not find setItemWidget in QTableView.
The corresponding method for model-view classes is QAbstractItemView::setIndexWidget().

wysota
27th November 2006, 10:37
Hi Wysota
Why not ? This was my last proposition, with the need to keep the index to setData in.

I didn't say to do that from setModelData...

The corresponding method for model-view classes is QAbstractItemView::setIndexWidget().

Right... Sometimes it's good to take a look at the docs before you write about some method ;)

lauranger
27th November 2006, 11:08
Hi again :)
For my second attempt, the one with the button, I am the one to blame :
I use my own sub-delegate and I "forgot" to relay the signals commitData
and closeEditor, as it is done when a view registers its delegate.
Sorry for the annoyance.
Regards