Results 1 to 3 of 3

Thread: How to define previous and next items to edit with a qtreeview/qabstractitemview

  1. #1
    Join Date
    Jan 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to define previous and next items to edit with a qtreeview/qabstractitemview

    Hi everybody

    I created a tree model subclassing QAbstractItemModelwhich I render using a QTreeView.

    When I edit an item and press the tab key, the editor jumps to the item in the next row, same column. I'd like the converse, I would like the editor to jump in the next column, same row.

    All I found in Qt Assistant was this mysterious statement :
    ... the current index defines the next and previous items to edit, ...
    in the documentation for QAbstractItemView::edit().
    Though, I don't understand how a QModelIndex may hold other indexes than parent's and children's.

    Thank you for lightning my candle,
    Mathieu

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to define previous and next items to edit with a qtreeview/qabstractitemview


  3. #3
    Join Date
    Jan 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to define previous and next items to edit with a qtreeview/qabstractitemview

    Thank, it is working great.

    Here is my code, if anyone needs an example. The cursor moves forwards/backwards in a row. If it reaches row end/beginning, it jumps to the next/previous row.
    Qt Code:
    1. QModelIndex MyTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
    2. {
    3. if(cursorAction == QAbstractItemView::MoveNext)
    4. {
    5. QModelIndex index = currentIndex();
    6. if(index.column() != 2)
    7. return model()->index(index.row(), index.column()+1, index.parent());
    8.  
    9. setCurrentIndex(model()->index(index.row(), 0, index.parent()));
    10. }
    11. else if(cursorAction == QAbstractItemView::MovePrevious)
    12. {
    13. QModelIndex index = currentIndex();
    14. if(index.column() != 0)
    15. return model()->index(index.row(), index.column()-1, index.parent());
    16.  
    17. setCurrentIndex(model()->index(index.row(), 2, index.parent()));
    18. }
    19.  
    20. return QTreeView::moveCursor(cursorAction, modifiers);
    21. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTreeView edit() not working.
    By billw in forum Qt Programming
    Replies: 0
    Last Post: 20th August 2010, 17:26
  2. Replies: 2
    Last Post: 20th August 2010, 05:18
  3. QAbstractItemView and updating selected items
    By Isaac in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 12:23
  4. Edit items in table model
    By gyre in forum Newbie
    Replies: 2
    Last Post: 14th January 2008, 03:08
  5. Edit items on QTreeView + QDirModel
    By junior0007 in forum Qt Programming
    Replies: 4
    Last Post: 23rd November 2007, 07:16

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.