Important: Please read the Qt Code of Conduct -

How to create a menu with focusable items instead of QActions

  • Hello everyone,

    I am developing a GUI for a project that has a touch screen and rotary encoder. I need to create a dropdown menu that will be used as a "Settings Menu," and it will have buttons such as Brightness, Sound, etc., that are accessible with the use of a rotary encoder. Everything works very well with a touch screen, but this menu should also be usable with a rotary encoder for the sake of my project.

    My problem is, I could only create a menu with actions, and these actions are not "buttons," so that they are not focusable. To use this menu with a rotary encoder, items of this menu should be focusable and clickable. Is there a way to do this? I also want to indicate that I have two classes, "Screens," in the MainWindow. This "Settings" menu should be usable on both screens. The best way for me to add QPushButtons to the dropdown menu created by another QPushButton.

    Thank you in advance; I am open to all comments about this topic.

  • Lifetime Qt Champion

    Try to use
    it should allow anything in the QMenu.

    alt text

  • Hello, thanks for your help.

    I am a beginner in Qt; I looked at the class definition of your example but couldn't make it work for my purpose. Can you give an example of how to set focus property and add buttons to the menu using QWidgetAction.

    Thank you in advance.

Log in to reply