Results 1 to 1 of 1

Thread: Context menu on Cells of QTableWidget

  1. #1
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Question Context menu on Cells of QTableWidget

    I'm sorry that i created another topic about QTableWidget and Context menu, but after reading previous topics i could not realize the problem. So, please help me.

    i have QTableWidget on form. It's used for list of files. Table has 2 columns. First - it's number of row, second - name of file. So, i need create context menu, which will open only by click on tableWidget. That's not all. Also i need to check: click was performed on cell or on empty table?

    if found an example of context menu:
    in header:
    Qt Code:
    1. void contextMenuEvent( QContextMenuEvent * e );
    To copy to clipboard, switch view to plain text mode 
    then somewhere:

    Qt Code:
    1. QObject::connect (ui->tableWidget,SIGNAL(customContextMenuRequested(const QPoint &)),this,SLOT(contextMenuEvent(QContextMenuEvent*)));
    To copy to clipboard, switch view to plain text mode 

    and :

    Qt Code:
    1. void MainWindow::contextMenuEvent( QContextMenuEvent * e )
    2. {
    3.  
    4. QAction *pRemoveAction = new QAction("Remove from list",this);
    5. /*in this place i need something like
    6. if(cell_click())pRemoveAction->setEnabled(true); else
    7. pRemoveAction->setEnabled(true);
    8. */
    9. connect(pRemoveAction ,SIGNAL(triggered()),this,SLOT(toolButton_DeleteTrack_Clicked()));
    10. //
    11. QMenu *pContextMenu = new QMenu( this);
    12. pContextMenu->addAction(pRemoveAction );
    13. //
    14. pContextMenu->exec( e->globalPos() );
    15.  
    16. delete pContextMenu;
    17. pContextMenu = NULL;
    18. }
    To copy to clipboard, switch view to plain text mode 

    but this menu is open after clicking anywhere on the form((
    P.S. Sorry for my bad English
    Last edited by core_st; 19th October 2010 at 17:07.

Similar Threads

  1. problem with Context Menu in QTableWidget
    By andreime in forum Newbie
    Replies: 6
    Last Post: 7th September 2015, 08:44
  2. how to add a submenu to a context menu of a QTableWidget
    By berlinud in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2010, 14:38
  3. read QTableWidget cells
    By navid in forum Newbie
    Replies: 8
    Last Post: 4th April 2010, 10:40
  4. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52
  5. Context menu works slowly on QTableWidget
    By THRESHE in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 19:54

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.