How to create Pop up menu in Qt

  • 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?

  • Take a look on "Menus Example":

    Does it work for you ?

  • 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.

  • 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("Close"), this,SLOT(slotClose()));


    void Connection::slotClose()// Context Menu Option for 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.

Log in to reply