Results 1 to 11 of 11

Thread: Custom editor-delegate communication

  1. #1
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Custom editor-delegate communication

    I've got a custom editor (nothing fancy - a widget with a couple of buttons and a label on it), which is linked to a model by a simple custom delegate via QDataWidgetMapper. The delegate calls setEditorData() and everything is fine, until the time when user ends editing in the widget. At this point data should be relayed back to the model, but the delegate does not have any idea that user is done with the editor, so setModelData() does not get called. So the question is - how do I notify the delegate that it's time to commit the data to the model? Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom editor-delegate communication


  3. #3
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom editor-delegate communication

    I've seen this, but how can it be used in practice? It's a signal - but which slot should I connect it to? Or do I just call it as a method? If yes, then how can my editor widget know, which delegate it is connected to? It's just a widget. Do I need to explicitly pass a delegate reference to editor's widget's constructor?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom editor-delegate communication

    You don't have to connect the signal to anything, this is done somewhere in the view. You or rather your delegate is the one notifying the view about editing finished.

    There are several ways to get that signal emitted.

    Your editor could emit an "editing finished" signal that has the editor itself as its argument. In this case you can simply connect that signal to commitData.
    Your editor could emit a signal and you have a slot in your delegate that is connected to that and in that slot you emit commitData with the editor widget's pointer as its argument.
    You could pass the delegate to the editor and do a signal/signal connect there.
    You could add a method to your delegate that emits commitData, pass the delegate to the editor and have the editor call that method.

    Cheers,
    _

  5. #5
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom editor-delegate communication

    Sorry for the delay - was chased from my town by angry customers. Back to the topic...

    Quote Originally Posted by anda_skoa View Post
    You don't have to connect the signal to anything, this is done somewhere in the view. You or rather your delegate is the one notifying the view about editing finished._
    Whoops, forgot to mention a little detail - there is no view, the editor is placed on a QWidget and connected to the model through a QDataWidgetMapper. So, it's the editor who knows when the editing is finished.


    Quote Originally Posted by anda_skoa View Post
    There are several ways to get that signal emitted.
    Your editor could emit an "editing finished" signal that has the editor itself as its argument. In this case you can simply connect that signal to commitData._
    Can you be more specific? Connect to what object's commitData(), exactly? Delegate does not have a slot with the name "commitData", it has a signal with the same name. But I tried to do like you said - I declared MyEditorClass.editingFinished(QWidget) signal, connected myEditorInstance.editingFinished to myDelegateInstance.commitData, ensured that myEditorInstance.editingFinished.emit(myEditorInst ance) is called, and nothing is happening, i.e., myDelegateInstance.setModelData() is not called.


    Quote Originally Posted by anda_skoa View Post
    Your editor could emit a signal and you have a slot in your delegate that is connected to that and in that slot you emit commitData with the editor widget's pointer as its argument. _
    Tried that too: I declared MyEditorClass.editingFinished(QWidget) signal, declared MyDelegate.testSlot(QWidget), connected them, and inside testSlot() I did commitData.emit(editor). The myDelegateInstance.testSlot(editor) is called correctly, but that's it. Emitting myDelegate.commitData(editor) does not have any result.

    Quote Originally Posted by anda_skoa View Post
    You could pass the delegate to the editor and do a signal/signal connect there.
    You could add a method to your delegate that emits commitData, pass the delegate to the editor and have the editor call that method. _
    Could I see some code, please? An example, a tutorial - anything?

  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: Custom editor-delegate communication

    QDataWidgetMapper is the "view" in this case.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom editor-delegate communication

    Quote Originally Posted by wysota View Post
    QDataWidgetMapper is the "view" in this case.
    And what does that practically mean in the given case? QDataWidgetMapper does not have commitData() slot\signal\method. Is it supposed to emit it somehow by itself? If yes, then how do I "motivate" it to do that?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom editor-delegate communication

    Both things you tried should have worked.
    I've checked the code of QDataWidgetMapper and commitData doesn't do anything in the case that QDataWidgetMapper::submitPolicy is "Manual submit".

    You could try changing that to AutoSubmit or connecting some signal to QDataWidgetMapper::submit() or call submit manually.

    Cheers,
    _

  9. #9
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom editor-delegate communication

    It is set to AutoSubmit, actually. And standard editor widgets (QLineEdit etc) work perfectly.

  10. #10
    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: Custom editor-delegate communication

    Quote Originally Posted by AlexVhr View Post
    It is set to AutoSubmit, actually. And standard editor widgets (QLineEdit etc) work perfectly.
    Does your editor class have a USER property defined along with a NOTIFY signal for it? Do you have a mechanism for determining the user is done with using the editor? I think this is where NOTIFY signal for a USER property kicks in with default Qt editor widgets. Also have a look at QItemEditorFactory and QItemEditorCreator classes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom editor-delegate communication

    So far I've managed to make it work with Tab key, but clicking away is still not producing desired results. Here is the full test case, if someone cares to look at it (it's Python + PySide though)


    Added after 1 49 minutes:


    Ok, it looks like the problem was caused by my way of dealing with the fact that QDataWidgetMapper only supports a single delegate. After getting rid of my 'universal delegate' everything works using signals as it should. The only problem now is to get around that 'one delegate per QDataWidgetMapper' problem.
    Last edited by AlexVhr; 30th January 2013 at 11:42.

Similar Threads

  1. Delegate's editor won't launch in a custom inserted column
    By zeroknowledge in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2011, 16:21
  2. Replies: 1
    Last Post: 10th May 2011, 22:35
  3. Item Delegate editor background
    By LynneV in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2010, 21:33
  4. Replies: 1
    Last Post: 28th October 2009, 18:42
  5. Replies: 5
    Last Post: 10th August 2009, 10:50

Tags for this Thread

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.