Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QMenu C++ code help

QMenu C++ code help

Scheduled Pinned Locked Moved Unsolved C++ Gurus
6 Posts 3 Posters 637 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1
    This post is deleted!
    Axel SpoerlA 1 Reply Last reply
    0
    • A Anonymous_Banned275

      This post is deleted!

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by Axel Spoerl
      #2

      @AnneRanch
      I think many people in this forum are willing to do that.
      The way it works is as follows:

      • show code
      • explain what's the expected behavior
      • show error messages, if they exist
      • take advice, change the implementation accordingly
      • show more / other parts of the code, if asked to

      The way it doesn't work is like in this post, where unwanted arrows in a menu were reported. I asked for a screenshot of those arrows. Your response was, that screenshots of menus can't be made at all. You also insinuated that I should be aware of this restriction, and therefore I should not have asked for the impossible. I explained you how to make a screenshot of menus on your operating system. You may deem the screenshot irrelevant. Maybe it is. But it helps understand what you are aiming at and it expedites getting a solution. Co-operation is in your hands, not in ours.

      I am neither judging nor analyzing you. I am just stating, which effect some posts have on me and maybe other members of the community: They bounce me off.

      It's never too late for a fresh start.
      Ready for it?

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3
        This post is deleted!
        JonBJ 2 Replies Last reply
        0
        • A Anonymous_Banned275

          This post is deleted!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @AnneRanch
          As per @Axel-Spoerl's answer to you at https://forum.qt.io/topic/153820/qmenu-qaction-how-can-i-add-checked/2, you must have created a QAction for the QMenu to put a checkbox on it. He gave the code for that there.

          Thereafter you can access either (a) by maintaining (e.g. as a class member variable) the QAction * pointer to the QAction you created and added to the QMenu or (b) from a QMenu you can get at all its actions via menu->actions(). If you know the one you want is the only/first one, then obviously:

          QAction *action = menu->actions().at(0);    // assumes at least one action has been added
          action->setChecked(true);
          
          A 1 Reply Last reply
          1
          • JonBJ JonB

            @AnneRanch
            As per @Axel-Spoerl's answer to you at https://forum.qt.io/topic/153820/qmenu-qaction-how-can-i-add-checked/2, you must have created a QAction for the QMenu to put a checkbox on it. He gave the code for that there.

            Thereafter you can access either (a) by maintaining (e.g. as a class member variable) the QAction * pointer to the QAction you created and added to the QMenu or (b) from a QMenu you can get at all its actions via menu->actions(). If you know the one you want is the only/first one, then obviously:

            QAction *action = menu->actions().at(0);    // assumes at least one action has been added
            action->setChecked(true);
            
            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @JonB The issue in no longer "add check box" to main menu.
            The issue is how to add submenus when only QAction" is accessible.

            1 Reply Last reply
            0
            • A Anonymous_Banned275

              This post is deleted!

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @AnneRanch said in QMenu C++ code help:

              That is the issue - how to change "checkable" property when there is access only to QMenu.

              That is what you wrote. So I took the time to answer it exactly.

              You cannot get directly from a QAction * to the QMenu you put it on, unlike the other way round which you asked and is answered. However, you can use QList<QObject *> QAction::associatedObjects() const from a QAction and you should find the QMenu it has been added to among them. And you add submenus to a menu. Which answers the new question.

              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