Results 1 to 5 of 5

Thread: Open a pop up menu when right click on any cell of the table

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    1

    Default Re: Open a pop up menu when right click on any cell of the table

    Thank you very much for your valuable reply.....My problem is solved now with some of your help and some of mine coding.I am pasting the code also so that it can help others also...

    First create a signal and slot in main program like this

    connect(ui->tableWidget,SIGNAL(customContextMenuRequested(con st QPoint &)),this,SLOT(ProvideContextMenu(const QPoint &)));

    and then just create the slots functions for them like this....

    void MainWindow::ProvideContextMenu(const QPoint &pos)
    {

    item = ui->tableWidget->itemAt(pos);
    // QPoint globalPos = ui->tableWidget->mapToGlobal(pos);
    QAction *pAddAction = new QAction("Add",ui->tableWidget);
    connect(pAddAction,SIGNAL(triggered()),this,SLOT(n ewRow()));
    QAction *pRemoveAction = new QAction("Remove",ui->tableWidget);
    connect(pRemoveAction ,SIGNAL(triggered()),this,SLOT(deleteRow()));
    QAction *pUpdateAction = new QAction("Update",ui->tableWidget);
    //connect(pUpdateAction ,SIGNAL(triggered()),this,SLOT(Update()));
    QMenu *pContextMenu = new QMenu( this);
    pContextMenu->addAction(pAddAction);
    pContextMenu->addAction(pRemoveAction );
    pContextMenu->addAction(pUpdateAction );
    pContextMenu->exec( mapToGlobal(pos) );
    delete pContextMenu;
    pContextMenu = NULL;
    }

    void MainWindow::newRow()
    {
    int row = ui->tableWidget->rowCount();
    ui->tableWidget->insertRow(row);
    }

    void MainWindow::deleteRow()
    {
    int row = ui->tableWidget->row(item);
    ui->tableWidget->removeRow(row);
    }


    Do not forget to declare them in .h file or wherever you want....
    Last edited by katta_ashish; 9th September 2010 at 07:23.

Similar Threads

  1. Replies: 0
    Last Post: 29th July 2009, 19:13
  2. QTreeView cell as table
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 09:45
  3. Making Table cell as a combobox?
    By kaushal_gaurav in forum Qt Programming
    Replies: 9
    Last Post: 1st August 2008, 12:04
  4. Replies: 4
    Last Post: 4th February 2008, 06:16
  5. Highlighting the border of cell in Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2006, 08:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.