Results 1 to 3 of 3

Thread: how to add context menu to the table widget header?

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default how to add context menu to the table widget header?

    Hi i added context menu to a table widget...
    But it is not displaying for table header...what changes i need to do?


    my context menu function is:
    Qt Code:
    1. void MainWindow::ProvideContextMenu(const QPoint &point)
    2. {
    3. QTableWidgetItem *item=filesTable->itemAt(point);
    4.  
    5.  
    6.  
    7. QPoint globalpos=filesTable->mapToGlobal(point);
    8. QString cell=item->text();
    9. cout<<"EVENT GENERATED..."<<cell.toStdString()<<endl;
    10.  
    11. QAction *pAddAction= new QAction("add",filesTable);
    12. QAction *pSplitAction= new QAction("SPLIT",filesTable);
    13. QMenu *pContextMenu = new QMenu( this);
    14. pContextMenu->addAction(pAddAction);
    15. pContextMenu->addAction(pSplitAction);
    16. pContextMenu->exec(globalpos);
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to add context menu to the table widget header?

    what changes i need to do?
    Since you code does not show us how you are summoning this menu it is hard to say.

    You need to stop cross-posting the same problem... it only serves to spread effort. Information that is present in the other thread is not automagically available here.

  3. #3
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to add context menu to the table widget header?

    Hi,
    I am success to create contextmenu in QTableView. I think this is same with QTableWidget. You can use this
    Qt Code:
    1. QHeaderView * QTableView::horizontalHeader () const
    To copy to clipboard, switch view to plain text mode 

    This is a sample code :
    Qt Code:
    1. QTableView *tblv;
    2. QHeaderView *horizontalHeader;
    3.  
    4. //connect horizontal header QTableView with contextmenu
    5. horizontalHeader = tblv->horizontalHeader();
    6. horizontalHeader->setContextMenuPolicy(Qt::CustomContextMenu); //set contextmenu
    7. connect(horizontalHeader, SIGNAL(customContextMenuRequested( const QPoint& )),
    8. this, SLOT(tablev_customContextMenu( const QPoint& )));
    To copy to clipboard, switch view to plain text mode 

    You can modified this with your problem. This site have a sample how to create contextmenu in QTableView. I think you can use that.
    http://toto-share.com/2011/07/contex...in-qtableview/

    Best regards,
    myta212

Similar Threads

  1. Replies: 1
    Last Post: 4th November 2011, 11:25
  2. Replies: 2
    Last Post: 3rd May 2011, 21:01
  3. context menu for table
    By sattu in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2011, 09:09
  4. Context Menu for specific items in a Tree Widget
    By manekineko in forum Qt Programming
    Replies: 0
    Last Post: 16th November 2009, 01:46
  5. Replies: 3
    Last Post: 5th March 2009, 07:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.