Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ChartView keyboard events
Qt 6.11 is out! See what's new in the release blog

ChartView keyboard events

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 485 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bob64
    wrote on last edited by
    #1

    Hi,

    I want to implement zooming/scrolling functionality on my use of ChartView and would like to provide the option of keyboard control. How to I detect a keyboard event on a ChartView?

    I tried the probably naive approach of adding a Keys.onPressed handler to the ChartView but it does not get triggered. Unlike an Item, ChartView has no focus property, so I tried overlaying a transparent rectangle on the ChartView, setting focus: true on it and moving the keyboard event handler to the rectangle instead, but still no luck. Frustratingly the documentation for ChartView.scrollDown (for example) says "This is a convenience method suitable for key navigation, for example", which suggests that it should be possible.

    Thanks in advance for any tips.

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

      I use separate input controls like RangeSlider QML Type for my axis config's.

      I also have a wrapper MouseArea that I use for Key inputs to interact with that, not my chart.
      I manually give and take focus according to the mouse, so keys don't interact after you've left the chart (MouseArea ) region.:

      MouseArea {
                     id: itemMouseArea   ;
                     anchors.fill: parent;
                     propagateComposedEvents: true
                     hoverEnabled: true  ;
                     onEntered: {
                         forceActiveFocus()
                     }
                     onExited: {
                         if (configVisible === false) {
                             itemMouseArea.focus = false;
                         }
                     }
                     Keys.onPressed: {
                         if (event.key === Qt.Key_Left) {
                             row.updateShared(++slider.value);
                         }
                         if (event.key === Qt.Key_Right) {
                             if ( slider.value > 1){
                                 row.updateShared(--slider.value);
                             }
                         }
                         event.accepted = true;
                     }
                 }
      
      B 1 Reply Last reply
      1
      • 6thC6 6thC

        I use separate input controls like RangeSlider QML Type for my axis config's.

        I also have a wrapper MouseArea that I use for Key inputs to interact with that, not my chart.
        I manually give and take focus according to the mouse, so keys don't interact after you've left the chart (MouseArea ) region.:

        MouseArea {
                       id: itemMouseArea   ;
                       anchors.fill: parent;
                       propagateComposedEvents: true
                       hoverEnabled: true  ;
                       onEntered: {
                           forceActiveFocus()
                       }
                       onExited: {
                           if (configVisible === false) {
                               itemMouseArea.focus = false;
                           }
                       }
                       Keys.onPressed: {
                           if (event.key === Qt.Key_Left) {
                               row.updateShared(++slider.value);
                           }
                           if (event.key === Qt.Key_Right) {
                               if ( slider.value > 1){
                                   row.updateShared(--slider.value);
                               }
                           }
                           event.accepted = true;
                       }
                   }
        
        B Offline
        B Offline
        Bob64
        wrote on last edited by
        #3

        @6thC Thank you!

        I already had a MouseArea on the plot area of my ChartView but I hadn't thought to try to handle key events there. I think the idea of using the mouse enter and exit handlers to manually manage the focus - and in particular the forceActiveFocus call - were what I was missing and what I needed.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved