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 Close QMenu
Qt 6.11 is out! See what's new in the release blog

How To Close QMenu

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 5.7k 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.
  • Taz742T Offline
    Taz742T Offline
    Taz742
    wrote on last edited by
    #1

    void Dialog::on_tableWidget_customContextMenuRequested(const QPoint &pos)
    {

    myMenu = new QMenu();
    
    QAction *editUserAction0 = myMenu->addAction("&რედაქტირება", this, SLOT(EditSLOT()));
    editUserAction0->setIcon(QIcon(":/SMSicons/edit.png"));
    editUserAction0->setEnabled(true);
    
    QAction *editUserAction1 = myMenu->addAction("&წაშლა", this, SLOT(RemoveSLOT()));
    editUserAction1->setIcon(QIcon(":/SMSicons/remove.png"));
    editUserAction1->setEnabled(true);
    
    myMenu->exec(ui->tableWidget->mapToGlobal(pos));
    

    }

    How can i do so after the slot to close off the menu?
    After performing the slot, he still appears.

    Do what you want.

    raven-worxR 2 Replies Last reply
    0
    • artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      Add delete myMenu; after the myMenu->exec();?

      For more information please re-read.

      Kind Regards,
      Artur

      Taz742T 1 Reply Last reply
      0
      • artwawA artwaw

        Add delete myMenu; after the myMenu->exec();?

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on last edited by
        #3

        @artwaw
        nothing

        Do what you want.

        1 Reply Last reply
        0
        • Taz742T Taz742

          void Dialog::on_tableWidget_customContextMenuRequested(const QPoint &pos)
          {

          myMenu = new QMenu();
          
          QAction *editUserAction0 = myMenu->addAction("&რედაქტირება", this, SLOT(EditSLOT()));
          editUserAction0->setIcon(QIcon(":/SMSicons/edit.png"));
          editUserAction0->setEnabled(true);
          
          QAction *editUserAction1 = myMenu->addAction("&წაშლა", this, SLOT(RemoveSLOT()));
          editUserAction1->setIcon(QIcon(":/SMSicons/remove.png"));
          editUserAction1->setEnabled(true);
          
          myMenu->exec(ui->tableWidget->mapToGlobal(pos));
          

          }

          How can i do so after the slot to close off the menu?
          After performing the slot, he still appears.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Taz742 said in How To Close QMenu:

          After performing the slot, he still appears.

          what do you mean? The menu stays visible?
          According to the code you've posted this won't happen.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          Taz742T 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @Taz742 said in How To Close QMenu:

            After performing the slot, he still appears.

            what do you mean? The menu stays visible?
            According to the code you've posted this won't happen.

            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by
            #5

            @raven-worx said in How To Close QMenu:

            what do you mean? The menu stays visible?

            YES.

            After clicking on the menu, I will show a dialogue.
            After disconnecting the dialogue I do not want the menu to be visible anymore.

            Do what you want.

            raven-worxR 1 Reply Last reply
            0
            • Taz742T Taz742

              @raven-worx said in How To Close QMenu:

              what do you mean? The menu stays visible?

              YES.

              After clicking on the menu, I will show a dialogue.
              After disconnecting the dialogue I do not want the menu to be visible anymore.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Taz742
              please post your code from the RemoveSLOT() and EditSLOT() slots.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              Taz742T 1 Reply Last reply
              0
              • Taz742T Taz742

                void Dialog::on_tableWidget_customContextMenuRequested(const QPoint &pos)
                {

                myMenu = new QMenu();
                
                QAction *editUserAction0 = myMenu->addAction("&რედაქტირება", this, SLOT(EditSLOT()));
                editUserAction0->setIcon(QIcon(":/SMSicons/edit.png"));
                editUserAction0->setEnabled(true);
                
                QAction *editUserAction1 = myMenu->addAction("&წაშლა", this, SLOT(RemoveSLOT()));
                editUserAction1->setIcon(QIcon(":/SMSicons/remove.png"));
                editUserAction1->setEnabled(true);
                
                myMenu->exec(ui->tableWidget->mapToGlobal(pos));
                

                }

                How can i do so after the slot to close off the menu?
                After performing the slot, he still appears.

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by raven-worx
                #7

                @Taz742
                in case you are creating another event loop in the slots you need to do this instead:

                void Dialog::on_tableWidget_customContextMenuRequested(const QPoint &pos)
                {
                
                myMenu = new QMenu();
                
                QAction *editUserAction0 = myMenu->addAction("&რედაქტირება");
                editUserAction0->setIcon(QIcon(":/SMSicons/edit.png"));
                editUserAction0->setEnabled(true);
                
                QAction *editUserAction1 = myMenu->addAction("&წაშლა",);
                editUserAction1->setIcon(QIcon(":/SMSicons/remove.png"));
                editUserAction1->setEnabled(true);
                
                QAction* action = myMenu->exec(ui->tableWidget->mapToGlobal(pos));
                
                if( action == editUserAction0  )
                     this->EditSLOT()
                else if ( action == editUserAction1 )
                    this->RemoveSLOT()
                }
                

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                Taz742T 1 Reply Last reply
                1
                • raven-worxR raven-worx

                  @Taz742
                  please post your code from the RemoveSLOT() and EditSLOT() slots.

                  Taz742T Offline
                  Taz742T Offline
                  Taz742
                  wrote on last edited by
                  #8

                  @raven-worx
                  I am Sorry.

                  Dialog::Dialog(QWidget *parent) :
                      QDialog(parent),
                      ui(new Ui::Dialog)
                  {
                      ui->setupUi(this);
                  
                      ui->tableWidget->setColumnCount(3);
                      ui->tableWidget->setColumnWidth(1, 120);
                      ui->tableWidget->setColumnWidth(2, 300 - 120);
                  
                      ui->tableWidget->hideColumn(0);
                  
                      ui->tableWidget->setHorizontalHeaderLabels(QStringList() << "" << "სახელი" << "ტელეფონი");
                      ui->tableWidget->verticalHeader()->hide();
                  
                      ShowContacts();
                  
                      ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
                      connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(on_tableWidget_customContextMenuRequested(QPoint)));
                  }
                  

                  I had another connection with the constructos. And he would have appeared twice of course.

                  Do what you want.

                  1 Reply Last reply
                  0
                  • raven-worxR raven-worx

                    @Taz742
                    in case you are creating another event loop in the slots you need to do this instead:

                    void Dialog::on_tableWidget_customContextMenuRequested(const QPoint &pos)
                    {
                    
                    myMenu = new QMenu();
                    
                    QAction *editUserAction0 = myMenu->addAction("&რედაქტირება");
                    editUserAction0->setIcon(QIcon(":/SMSicons/edit.png"));
                    editUserAction0->setEnabled(true);
                    
                    QAction *editUserAction1 = myMenu->addAction("&წაშლა",);
                    editUserAction1->setIcon(QIcon(":/SMSicons/remove.png"));
                    editUserAction1->setEnabled(true);
                    
                    QAction* action = myMenu->exec(ui->tableWidget->mapToGlobal(pos));
                    
                    if( action == editUserAction0  )
                         this->EditSLOT()
                    else if ( action == editUserAction1 )
                        this->RemoveSLOT()
                    }
                    
                    Taz742T Offline
                    Taz742T Offline
                    Taz742
                    wrote on last edited by
                    #9

                    @raven-worx said in How To Close QMenu:

                    QAction* action = myMenu->exec(ui->tableWidget->mapToGlobal(pos));

                    if( action == editUserAction0 )
                    this->EditSLOT()
                    else if ( action == editUserAction1 )
                    this->RemoveSLOT()
                    }

                    Oh its good.
                    Thank you for this.

                    Do what you want.

                    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