Results 1 to 7 of 7

Thread: How to change the QModelIndex with keyboard

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to change the QModelIndex with keyboard

    Dear All

    For QTreeView I would like to change the model index by arrow keys. When I press down key I would like the model index to change like I click on the row.... Is there any signal for this?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to change the QModelIndex with keyboard

    You have to reimp QWidget/QTreeView::keyPressEvent() or install an event handler if you want that functionality even if your treeview does not have the focus.

  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to change the QModelIndex with keyboard

    We have keyPressEvent but problem we have is,

    when we move with arrow keys on the tree, model index does not change...

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change the QModelIndex with keyboard

    AFAIK standard behavior is that you can change selection in views with arrow key by default. You can get signals from QItemSelectionModel which you can get with QTreeView::selectionModel()
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to change the QModelIndex with keyboard

    Dear My "Guru" friend...

    I have all ready tried your smart idea, but it didn't work! Thank you for your smart idea! The selection you are talking about could be done with mouse, I am talking a selection with a mouse, user should navigate around the tree without mouse....
    Last edited by aekilic; 27th February 2010 at 14:58.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to change the QModelIndex with keyboard

    Quote Originally Posted by aekilic View Post
    when we move with arrow keys on the tree, model index does not change...
    How does your code the move the selection look like? Normaly you cange with QAbstractItemView::setCurrentIndex() or directly via the selection model: selectionModel()->setCurrentIndex(/*...*/).

  7. #7
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to change the QModelIndex with keyboard

    Sorry for the late replies

    The problem I had was from the qkeyevent,

    Normaly on the widget when users hits to arrov key tree view comes to focus, and after that widget does not listen the key event... So there is no signal to get the selection. Do I need to re implement qtreeview?

Similar Threads

  1. QModelIndex question
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 10th February 2010, 01:53
  2. invalid QModelIndex
    By Talei in forum Newbie
    Replies: 1
    Last Post: 18th January 2010, 20:21
  3. Problem with QModelIndex
    By Kesy in forum Qt Programming
    Replies: 6
    Last Post: 30th October 2008, 08:44
  4. QModelIndex problem!
    By landonmkelsey in forum Qt Programming
    Replies: 10
    Last Post: 28th August 2008, 19:46
  5. Replies: 3
    Last Post: 7th May 2006, 17:07

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
  •  
Qt is a trademark of The Qt Company.