Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget: How to intercept up/down arrow keys
Forum Updated to NodeBB v4.3 + New Features

QTableWidget: How to intercept up/down arrow keys

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.1k 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.
  • P Offline
    P Offline
    Publicnamer
    wrote on last edited by
    #1

    I have some cells in my table that are marked as non-selectable. This is impeding the up/down arrow keys.
    E.g. in a 3x3 table perhaps cell 1,1 is non-selectable. But I want to have my code decide where to move the selection next
    when the up/down keys are pressed.
    How can I intercept these key-presses?
    Thanks.

    jsulmJ 1 Reply Last reply
    0
    • P Publicnamer

      I have some cells in my table that are marked as non-selectable. This is impeding the up/down arrow keys.
      E.g. in a 3x3 table perhaps cell 1,1 is non-selectable. But I want to have my code decide where to move the selection next
      when the up/down keys are pressed.
      How can I intercept these key-presses?
      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Publicnamer Did you subclass QTabWidget and override https://doc.qt.io/qt-6/qwidget.html#keyPressEvent?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        I think it might be easier to reimplement moveCursor (https://doc.qt.io/qt-6/qabstractitemview.html#moveCursor)

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        P 1 Reply Last reply
        3
        • VRoninV VRonin

          I think it might be easier to reimplement moveCursor (https://doc.qt.io/qt-6/qabstractitemview.html#moveCursor)

          P Offline
          P Offline
          Publicnamer
          wrote on last edited by Publicnamer
          #4

          @VRonin I just tried moveCursor. I am finding that sometimes moveCursor is not being called in response to up/down arrows. Typically it is right after I have called setCurrentCell.

          @jsulm I also just tried keyPressEvent and I find it's not being called in the same situation.

          In each case, the arrow keys are ignored until I click somewhere in the table, even though I had just been interacting with the table.

          VRoninV 1 Reply Last reply
          0
          • P Publicnamer

            @VRonin I just tried moveCursor. I am finding that sometimes moveCursor is not being called in response to up/down arrows. Typically it is right after I have called setCurrentCell.

            @jsulm I also just tried keyPressEvent and I find it's not being called in the same situation.

            In each case, the arrow keys are ignored until I click somewhere in the table, even though I had just been interacting with the table.

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @Publicnamer said in QTableWidget: How to intercept up/down arrow keys:

            even though I had just been interacting with the table.

            Does the tablewidget have focus? you might be moving the focus on another widget in another operation

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            P 1 Reply Last reply
            2
            • VRoninV VRonin

              @Publicnamer said in QTableWidget: How to intercept up/down arrow keys:

              even though I had just been interacting with the table.

              Does the tablewidget have focus? you might be moving the focus on another widget in another operation

              P Offline
              P Offline
              Publicnamer
              wrote on last edited by Publicnamer
              #6

              @VRonin Yes, that was it, thanks. Movecursor is working fine now.

              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