Results 1 to 3 of 3

Thread: Update active editor in delegate when value underneath changes

  1. #1
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Update active editor in delegate when value underneath changes

    Hi all,

    I have a QTableView with a custom model underneath and delegates to render the view in different ways.
    If I e.g. change a double value, I use a QDoubleSpinBox which works fine.
    However, it is possible that the value that is currently edited is changing due to another mechanism. Then, the model is informed of the change and emits dataChanged(). But then, the value in the already open spinbox does not change.

    How do I inform the editor (QDoubleSpinBox) that it should update its value while it is active?
    When I close the editor and change to another cell, the value is correctly updated but not _while_ I am editing it.

    Any help appreciated.

    Regards,

    Rainer

  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: Update active editor in delegate when value underneath changes

    You can connect to the dataChanged() signal, check if there is an editor opened for one of the modified indexes and call QAbstractItemDelegate::setEditorData().

  3. #3
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Update active editor in delegate when value underneath changes

    Quote Originally Posted by wysota View Post
    You can connect to the dataChanged() signal, check if there is an editor opened for one of the modified indexes and call QAbstractItemDelegate::setEditorData().
    Thanks for your help.
    That's what I was thinking, too. I just didn't know how to check for an opened editor.
    This is what you have to do:
    Connect the dataChanged signal to a custom slot updateEditor.
    In your custom model, you need a pointer to the view, called tview here.
    Then, in customEditor, you can call indexWidget on the view which returns the editor widget. Here a sample code:

    Qt Code:
    1. void MyDelegate::updateEditor(const QModelIndex& start, const QModelIndex& end)
    2. {
    3. QWidget* widget = tview->indexWidget(start);
    4.  
    5. if (widget)
    6. {
    7. switch(start.column())
    8. {
    9. // edit only these columns, leave out others
    10. case col1:
    11. case col2:
    12. case col4:
    13. {
    14. setEditorData(widget, start);
    15. break;
    16. }
    17. default:
    18. break;
    19. }
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    Of course, you have to do some more necessary checks.
    If there is an easier way, please let me know.

    Regards,

    Rainer

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.