Results 1 to 3 of 3

Thread: Model/View: Custom Persistent Editor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2006
    Posts
    35
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Model/View: Custom Persistent Editor

    I created a simple ItemDelegate that shows a custom editor on one of my TableView columns. Editing the items in this column works perfectly when using the standard mechanism (double-click on cell, make changes in editor, select another cell).

    I made a change that the editor will be opened persistent on the current selected row:

    Qt Code:
    1. void MainWindow::ruleTableViewSelectedRowChanged(const QModelIndex & current, const QModelIndex & previous)
    2. {
    3. // Update persistent InputColumn editor.
    4. ruleTableView->closePersistentEditor(ruleTableView->model()->index(previous.row(), RuleTableModel::InputColumn));
    5. ruleTableView->openPersistentEditor(ruleTableView->model()->index(current.row(), RuleTableModel::InputColumn));
    To copy to clipboard, switch view to plain text mode 

    Now changes to the editor will not be saved when changing the row unless I hit enter while having the editor selected.

    I tried the behaviour of a standard ItemDelegate (SpinBox) and the changes to it will be saved, so I assume I need to change my custom ItemDelegate to commit changes directly when something is changed and not only when setModelData gets called?

    Thanks in advance,
    -Jens

  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: Model/View: Custom Persistent Editor

    Call QAbstractItemDelegate::commitData() on your editor before closing it.

  3. The following user says thank you to wysota for this useful post:

    No-Nonsense (7th February 2007)

  4. #3
    Join Date
    Nov 2006
    Posts
    35
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Model/View: Custom Persistent Editor

    Quote Originally Posted by wysota View Post
    Call QAbstractItemDelegate::commitData() on your editor before closing it.
    How would I do this? QItemDelegate only has methods to create an editor but deletes it on its own.

    I had a look at the Qt doc example http://doc.trolltech.com/4.2/itemvie...xdelegate.html and they want me to install an event filter: "We install an event filter on the spin box to ensure that it behaves in a way that is consistent with other delegates. The implementation for the event filter is provided by the base class."

    I then had a look at QItemDelegate but there they do not install an event filter in createEditor so why should I do (I tried and it did not help with my problem).

    Why do the standard Qt ItemDelegates (QComboBox, QSpinBox, QLineEdit) work as expected? When do they call commitData?

    Thanks in advance,
    -Jens

Similar Threads

  1. Replies: 5
    Last Post: 16th May 2006, 20:38
  2. Replies: 12
    Last Post: 15th February 2006, 10:46

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.