Results 1 to 7 of 7

Thread: QItemDelegate signals

  1. #1
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QItemDelegate signals

    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

  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: 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.

  3. #3
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QItemDelegate signals

    Quote Originally Posted by wysota View Post
    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

  4. #4
    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: 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.

  5. #5
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default 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.

  6. #6
    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: QItemDelegate signals

    Quote Originally Posted by Micawber View Post
    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().

  7. #7
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default 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 View Post
    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 View Post
    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?

Similar Threads

  1. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  2. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18
  3. premature call to setmodeldata with QItemDelegate
    By placebo in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2007, 17:39
  4. QGraphicsItem and signals
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 11:19
  5. KDE Signals
    By chombium in forum KDE Forum
    Replies: 1
    Last Post: 25th January 2006, 18:45

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.