Results 1 to 2 of 2

Thread: premature call to setmodeldata with QItemDelegate

  1. #1
    Join Date
    Nov 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default premature call to setmodeldata with QItemDelegate

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: premature call to setmodeldata with QItemDelegate

    Why not reimplement setModelData to only affect the model if there is anything sane entered in the line edit?

Similar Threads

  1. setModelData for subclassed QItemDelegate
    By T4ng10r in forum Qt Programming
    Replies: 7
    Last Post: 27th May 2007, 12:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.