Results 1 to 5 of 5

Thread: Capturing Key_up and Key_down for QTreeView

  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Capturing Key_up and Key_down for QTreeView

    I've attempted to capture key press events by both overriding keyPressEvent and event, but I am only able to capture the right arrow and left arrow keys. Any examples would help. I searched the forum...but all examples don't seem to work for me.

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Capturing Key_up and Key_down for QTreeView

    Could we see some code? I don't have any problems catching Qt::Key_Up or Qt::Key_Down in keyPressEvent().
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Capturing Key_up and Key_down for QTreeView

    Unfortunately my dev machine crashed the other day...so I no longer have that code. However, looking at the situation I'm wondering if I'm over-complicating the problem.

    I want to call a function whenever a new row is selected within a QTreeView. Right now I have this QTreeView connected using both the "entered" and "pressed" signal. This works fine as long as the user clicks and selects a new row. However, if the user uses the up and down arrow keys to change rows, my function does not get called. Rather then capturing the up and down arrow keys, is there an easier way to capture this event?

    Thanks in advance.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Capturing Key_up and Key_down for QTreeView

    Yeah, you can use QAbstractItemView::selectionModel() to retrieve the item selection model and connect to one of it's signals, like QItemSelectionModel::selectionChanged().
    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Capturing Key_up and Key_down for QTreeView

    Thanks JPN...I'll give that a shot!

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.