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. Main menu set with submenu - triggering issue
QtWS25 Last Chance

Main menu set with submenu - triggering issue

Scheduled Pinned Locked Moved Unsolved C++ Gurus
5 Posts 4 Posters 617 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 19 Jan 2024, 17:22 last edited by
    #1

    I have QMenu with sub QMenu
    I can trigger on submenu OK.
    I wanted to be able to trigger on maim menu to run all the submenu options.
    I can attempt to set the check box - trigger - and it reacts ( turns grey ) but no connect is generated and no "check mark " either.

    My question is - can that be even done in Qt?

       // build main menu TOK
                        subMenu[index]  = m_ui->menuWindow_cpntrol;
                        subMenu[index] = subMenu[index]
                                ->addMenu(list[index] + " # " + QString::number(index));
                        subAction[index] = subMenu[index]->addMenu(subMenu[index]);
                        subAction[index]->setVisible(true);
                        subAction[index]->setCheckable(true);
                        // TOK subAction[index]->setText("DEBUG test main menu ");
    
    
                        // connect to main submenu
                        connect(subMenu[index] , &QMenu::triggered, this ,
                                [=]() { this->processAction(index,index) ;});
    
    
    
    A T 2 Replies Last reply 19 Jan 2024, 18:01
    0
    • A Anonymous_Banned275
      19 Jan 2024, 17:22

      I have QMenu with sub QMenu
      I can trigger on submenu OK.
      I wanted to be able to trigger on maim menu to run all the submenu options.
      I can attempt to set the check box - trigger - and it reacts ( turns grey ) but no connect is generated and no "check mark " either.

      My question is - can that be even done in Qt?

         // build main menu TOK
                          subMenu[index]  = m_ui->menuWindow_cpntrol;
                          subMenu[index] = subMenu[index]
                                  ->addMenu(list[index] + " # " + QString::number(index));
                          subAction[index] = subMenu[index]->addMenu(subMenu[index]);
                          subAction[index]->setVisible(true);
                          subAction[index]->setCheckable(true);
                          // TOK subAction[index]->setText("DEBUG test main menu ");
      
      
                          // connect to main submenu
                          connect(subMenu[index] , &QMenu::triggered, this ,
                                  [=]() { this->processAction(index,index) ;});
      
      
      
      A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 19 Jan 2024, 18:01 last edited by
      #2

      @AnneRanch
      This has been answered at length in this post. The summary is: It's better to keep track of your QAction objects and connect to their triggered signal.
      The connect statement is syntactically correct. It will call the lambda each time an action of subMenu[index] is triggered. The information, which action (i.e. which line of the menu) was selected, is lost. The code is unlikely to produce a meaningful result.

      I think that you mix up actions and menus. That has lead to an architectural problem. It can be fixed by code refactoring,

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      1
      • A Anonymous_Banned275
        19 Jan 2024, 17:22

        I have QMenu with sub QMenu
        I can trigger on submenu OK.
        I wanted to be able to trigger on maim menu to run all the submenu options.
        I can attempt to set the check box - trigger - and it reacts ( turns grey ) but no connect is generated and no "check mark " either.

        My question is - can that be even done in Qt?

           // build main menu TOK
                            subMenu[index]  = m_ui->menuWindow_cpntrol;
                            subMenu[index] = subMenu[index]
                                    ->addMenu(list[index] + " # " + QString::number(index));
                            subAction[index] = subMenu[index]->addMenu(subMenu[index]);
                            subAction[index]->setVisible(true);
                            subAction[index]->setCheckable(true);
                            // TOK subAction[index]->setText("DEBUG test main menu ");
        
        
                            // connect to main submenu
                            connect(subMenu[index] , &QMenu::triggered, this ,
                                    [=]() { this->processAction(index,index) ;});
        
        
        
        T Offline
        T Offline
        TomZ
        wrote on 20 Jan 2024, 12:03 last edited by
        #3

        @AnneRanch said in Main menu set with submenu - triggering issue:

        My question is - can that be even done in Qt?

        No.

        A menu either opens a submenu or it triggers an action on click.

        A 1 Reply Last reply 20 Jan 2024, 13:01
        0
        • T TomZ
          20 Jan 2024, 12:03

          @AnneRanch said in Main menu set with submenu - triggering issue:

          My question is - can that be even done in Qt?

          No.

          A menu either opens a submenu or it triggers an action on click.

          A Offline
          A Offline
          Anonymous_Banned275
          wrote on 20 Jan 2024, 13:01 last edited by
          #4

          @TomZ Then I will have a submenu which will run all the tasks. Easy , and remove the check box on the main menu because it cannot work...Thanks

          J 1 Reply Last reply 20 Jan 2024, 13:57
          0
          • A Anonymous_Banned275
            20 Jan 2024, 13:01

            @TomZ Then I will have a submenu which will run all the tasks. Easy , and remove the check box on the main menu because it cannot work...Thanks

            J Offline
            J Offline
            JonB
            wrote on 20 Jan 2024, 13:57 last edited by JonB
            #5

            @AnneRanch
            You may have been trying to do what I did some time ago, but discovered it does not work so is not allowed in Qt. If you have a sub-menu on a menu --- i.e. the menu has that > you click on to "slide out" the sub-menu --- then although Qt allows you also put a checkbox on the parent menu item which has the > slide-out it actually does not work correctly for checking the box, and cannot be made to do so. Do not try to put a checkbox on a menu item which has a child menu slide-out.

            1 Reply Last reply
            0

            4/5

            20 Jan 2024, 13:01

            • Login

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