Results 1 to 7 of 7

Thread: problem with Context Menu in QTableWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: problem with Context Menu in QTableWidget

    genius... it works like a charm ! thank you.
    now for the other part.. how do you think i should check and allow the context menu to appear only when i click on a TableWidgetItem?

  2. #2
    Join Date
    Feb 2008
    Posts
    98
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 24 Times in 24 Posts

    Default Re: problem with Context Menu in QTableWidget

    You may get the index at the cursor position and check whether it's valid:

    Qt Code:
    1. void fileHandler::ctxMenu(const QPoint &pos)//started
    2. {
    3. QModelIndex index = m_ui->tableWidget->indexAt(pos);
    4. if(!index.isValid())
    5. return;
    6.  
    7. QMenu *menu = new QMenu;
    To copy to clipboard, switch view to plain text mode 

    Another way, getting the QTableWidgetItem:

    Qt Code:
    1. void fileHandler::ctxMenu(const QPoint &pos)//started
    2. {
    3. QTableWidgetItem *item = m_ui->tableWidget->itemAt(pos);
    4. if(!item)
    5. return;
    6.  
    7. QMenu *menu = new QMenu;
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to victor.fernandez for this useful post:

    andreime (3rd August 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: problem with Context Menu in QTableWidget

    thank you alot for the help

  5. #4
    Join Date
    Jul 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: problem with Context Menu in QTableWidget

    Many Thanks numbat !
    Only menu->exec(m_ui->tableWidget->viewport()->mapToGlobal(pos)); works correctly.

Similar Threads

  1. context menu advice
    By larry104 in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2025, 18:24
  2. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52
  3. Replies: 3
    Last Post: 5th March 2009, 07:27
  4. Menu problem using Designer
    By JimBrown in forum Qt Tools
    Replies: 1
    Last Post: 19th February 2007, 21:47
  5. Problem inserting in QTableWidget
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2006, 00:10

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.