PDA

View Full Version : premature call to setmodeldata with QItemDelegate



placebo
25th November 2007, 17:29
Greetings Qt-wizards,

In a feeble attempt to solve my problem I now try this forum to see if anyone well-versed in the mysteries of Qt can help me out.

The Context : I have a listeview with N entries which shows a text which relates an id to a path (eg. "root=/mypath"). When I click each entry, using a QItemDelegate, I create an editor-widget which consists of a QLineEdit and a QToolButton. The main idea is to either press the QLineEdit area to manually insert path or by pressing the QToolButton launching a dialog through QFileDialog::getExistingDirectory. When the dialog is closed I insert the path into my QLineEdit which I then want to use as the modeldata.

In Designer it looks like this:

QWidget (ZFilePathWidget)
--QHBoxLayout
----QLineEdit
----QToolButton

Problem: When the editor is created the QLineEdit has focus (which is good), but when I press the QToolButton to solve an absolute path setModelData is called in my QItemDelegate derivative. This is bad since at that time it uses whatever is in the QLineEdit and not the path I navigate to through the getExistingDirectory-dialog.

As found elsewhere through google I have implemented a commitAndCloseEditor() which I have hooked up to my editorwidget but still it seems that setModelData is called before ever entering commitAndCloseEditor.

Suspecting that somehow an event is send when I press the QToolButton (having focus in the QLineEdit) I have created an eventfilter in order to test this, but even when by purpose not calling down through QWidget::eventFilter the same problem still occurs.

To me it seems like somehow my QItemDelegate, which has created a ZFilePathWidget, gets some sort of event which triggers setModelData whenever focus is lost on QLineEdit. When setting a breakpoint in setModelData I can see that the function is called outside of the installed eventfilter which leads me to suspect that it's some other sort of automated functionality I am unaware of.

Looking at Assistant there seems to be very little information about exactly what events or happenings that triggers QItemDelegate::setModelData.

Does anyone have any pointers, clues or ideas?

Cheers

/placebo

wysota
25th November 2007, 17:39
Why not reimplement setModelData to only affect the model if there is anything sane entered in the line edit?