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 create Pop up menu in Qt
Forum Updated to NodeBB v4.3 + New Features

How to create Pop up menu in Qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 10.6k Views 1 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.
  • M Offline
    M Offline
    Mittu
    wrote on last edited by
    #1

    I have added a tableview in the form. I want to display a pop-up menu with only the cut, copy, selected item options when the user clicks ( right click) on the tableview. How can I achieve this ?Any idea or code available?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      Take a look on "Menus Example":http://qt-project.org/doc/qt-5/qtwidgets-mainwindows-menus-example.html

      Does it work for you ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mittu
        wrote on last edited by
        #3

        In my project am already implemented the menu option in menu bar.About my doubt now i want to implement a pop up menu when the user right click on the tableview.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          Maybe this "link":http://qt-project.org/search?search=QTableView+contextmenu will help you.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mittu
            wrote on last edited by
            #5

            Thanks.That was really hepful.
            @void Connection::customMenuRequested(QPoint pos)
            {
            //Context Menu Creation

            QModelIndex index=ui->tableView_2->indexAt(pos);
            QModelIndex index1=ui->tableView->indexAt(pos);
            QModelIndex index2=ui->tableView_3->indexAt(pos);

            QMenu *menu=new QMenu(this);
            
            menu->addAction(QString("Copy"), this,SLOT(slotCopy()));
            menu->addAction(QString("Cut"), this,SLOT(slotCut()));
            menu->addAction(QString("Paste"),this,SLOT(slotPaste()));
            menu->addAction(QString("Select"),this,SLOT(slotSelect()));
            menu->addAction(QString("Close"), this,SLOT(slotClose()));
            

            menu->popup(ui->tableView_2->viewport()->mapToGlobal(pos));
            menu->popup(ui->tableView->viewport()->mapToGlobal(pos));
            menu->popup(ui->tableView_3->viewport()->mapToGlobal(pos));

            }
            void Connection::slotClose()// Context Menu Option for Close
            {
            this->close();
            }
            @
            When i was right click the tablview the context menu will be displayed and also working the close menu option. But i dn't knw how to write the code for cut,copy,paste, select. I searched in Google. But couldn’t find any examples out there.

            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