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 . QAction how can I add "checked "?

QMenu . QAction how can I add "checked "?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 2 Posters 742 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
      #2

      @AnneRanch
      A menu can't be made checkable, but an action can.
      This alters your code to make the first action you add checkable.

      subMenu[ index_main] = m_ui->menuWindow_cpntrol->addMenu("DEBUG " + list[ index_main] + " #" + QString::number( index_main));
      
      QAction *checkableAction = subMenu[index_main]->addAction("Test checkable action");
      checkableAction->setCheckable(true); // makes it checkable, unchecked by default.
      checkableAction->setChecked(true); // makes it checked
      
              //subMenu[ index_main]->checkable(true);
              subMenu[ index_main]->setVisible(true);
              //subMenu[ index_main]->setCheckable(true);
      

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      1
      • JonBJ JonB referenced this topic on
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3
        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
          #4

          @AnneRanch
          I used the provided code.
          It shows the mechanism of making an action checkable and changing the checked property.
          That works with any action, no matter where in the menu tree it is located.
          You can use it in the main menu just as well.
          Or you can post the code that creates the main menu.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5
            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
              #6

              @AnneRanch
              Could you post all the code responsible for creating menus and submenus? I am getting lost, because I don’t see the big picture. Could you also sketch the desired menu structure, including checkboxes on actions?

              Software Engineer
              The Qt Company, Oslo

              A 1 Reply Last reply
              0
              • Axel SpoerlA Axel Spoerl

                @AnneRanch
                Could you post all the code responsible for creating menus and submenus? I am getting lost, because I don’t see the big picture. Could you also sketch the desired menu structure, including checkboxes on actions?

                A Offline
                A Offline
                Anonymous_Banned275
                wrote on last edited by
                #7

                FINALLY...

                here a current WORKING as expected - both menu and submenu have check boxes and only main menu has "arrows"....

                Unless there are objections I am going to clean up the worthless code...

                Thanks foe sticking with the problem...

                        mainAction[index_main] = m_ui->menuWindow_cpntrol->addAction(list[ index_main] + " #" + QString::number( index_main));
                        mainAction[index_main]->setCheckable(true);
                        //adds arrows
                        mainAction[index_main]->setMenu(tempmenu);
                        subAction[index_main] = tempmenu->addAction(list_hcitool[ index_main] + " #" + QString::number( index_main));
                        subAction[index_main]->setCheckable(true);
                
                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