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. Is it possible for a QPushButton to be invoked only with mouse click and not with the keyboard?
Forum Updated to NodeBB v4.3 + New Features

Is it possible for a QPushButton to be invoked only with mouse click and not with the keyboard?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 793 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Minas
    wrote on last edited by
    #1

    Hi forum!

    Is it possible for a QPushButton to be invoked only with mouse click and not with the keyboard?

    It's about a QTableView column with buttons.

    Minas

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Derive from QPushButton and disallow keyboard inputs by overwriting keyPressEvent()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        In addition to the suggestion of @Christian-Ehrlicher, you can also implement an event filter to "eat" the keyboard related events of the push button you don’t want to be keyboard activated.

        Out of curiosity, why do you want that behavior ? That’s going to be a bit counter-intuitive for your users.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 2 Replies Last reply
        1
        • SGaistS SGaist

          Hi,

          In addition to the suggestion of @Christian-Ehrlicher, you can also implement an event filter to "eat" the keyboard related events of the push button you don’t want to be keyboard activated.

          Out of curiosity, why do you want that behavior ? That’s going to be a bit counter-intuitive for your users.

          M Offline
          M Offline
          Minas
          wrote on last edited by
          #4

          @SGaist Thank you for your answers!

          I've done the first, i'll try for the second!

          I have a subclass of QStyledItemDelegate for a QTableView button column and the way I have implemented it, if the user invokes a button by pressing a key (spacebar or return), I'm not able to know in which row was that button.

          Minas

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            In addition to the suggestion of @Christian-Ehrlicher, you can also implement an event filter to "eat" the keyboard related events of the push button you don’t want to be keyboard activated.

            Out of curiosity, why do you want that behavior ? That’s going to be a bit counter-intuitive for your users.

            M Offline
            M Offline
            Minas
            wrote on last edited by
            #5

            @SGaist With your solution, I don't have to subclass QPushButton, thank's!

            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