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. How to assign a hotkey to a QCombobox?

How to assign a hotkey to a QCombobox?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 780 Views 2 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
    MasterBlade
    wrote on last edited by
    #1

    Hello I have a Qcombobox. When I open its drop-down menu, is there a way to assign a hotkey to each menus?

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

      Hi,

      What behaviour do you have in mind ?

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What behaviour do you have in mind ?

        M Offline
        M Offline
        MasterBlade
        wrote on last edited by
        #3

        @SGaist said in How to assign a hotkey to a QCombobox?:

        Hi,

        What behaviour do you have in mind ?

        For example, when I open this drop-down box, I can press 'A' to select "Activated (A)".
        0_1535101740130_1.png

        1 Reply Last reply
        0
        • AndeolA Offline
          AndeolA Offline
          Andeol
          wrote on last edited by
          #4

          I think just calling the QComboBox::setCurrentIndex(int index) method should do the trick.

          If you just call it as a response to the key pressed, you should get the behavior you want.
          Now there is the question: who detects the keypress ? Should those hotkeys always be active, no matter which widget has focus ? If that's what you want, you can set an eventfilter on the whole application. Be carefull, though. As your application becomes bigger, global hotkeys probably quickly stop being a good idea.

          When I open this drop-down box

          If that's the only time the hotkey is active, then you can set the filter on the QComboBox alone, or (cleaner) inherit from QComboBox to overwrite QWidget::keyPressEvent.

          Developer for R++ : https://rplusplus.com/

          1 Reply Last reply
          2

          • Login

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