Results 1 to 8 of 8

Thread: No reaction after right clicking on the QTableWidget's headers

  1. #1
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default No reaction after right clicking on the QTableWidget's headers

    Hi!

    I have set the headers for my QTableWidget and want to perform some actions by right clicking on them, but I am failing. That means, I am not able to display the menu. Does anyone already have such problem? How to overcome it? However, any right click on a given cell of the corresponding column/row displays the menu.

    Many thanks in advance.

    Here is my code:

    Qt Code:
    1. void MyWindow::showContextMenu(const QPoint &pos)
    2. {
    3. QMenu *menu = new QMenu(this);
    4.  
    5. m_insererRow = menu->addAction("Inser row here");
    6.  
    7. QAction *selectedItem = menu->exec(QCursor::pos());
    8.  
    9. // Some actions...
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Stanfillirenfro; 2nd April 2014 at 10:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: No reaction after right clicking on the QTableWidget's headers

    How does your code relate to a QTableWidget?
    Is MyWindow a QTableWidget subclass?
    How are you calling showContextMenu()?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No reaction after right clicking on the QTableWidget's headers

    Thanks Ando_skoa for your reply.


    Is MyWindow a QTableWidget subclass?
    Yes, MyWindow is a QtableWidget subclass.

    How are you calling showContextMenu()?
    Please have a look at the line 5 of .cpp

    MyWindow is a widget having a QWidget as parent.

    .h
    Qt Code:
    1. class AWindow: public QDialog
    2. {
    3. Q_OBJECT
    4. public:
    5. MyWindow(QWidget *parent = 0)
    6.  
    7. public slots:
    8. void showContextMenu(const QPoint &pos);
    9.  
    10. private:
    11.  
    12. QTableWidget *m_MyWindow;
    13. };
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. MyWindow::MyWindow(QWidget *parent): QDialog(parent)
    2. {
    3. m_mywindow = new QTableWidget(this);
    4.  
    5. connect(m_myWindow, SIGNAL(customContextMenuRequested(const QPoint)), this, SLOT(showContextMenu(const QPoint)));
    6. }
    7.  
    8. void MyWindow::showContextMenu(const QPoint &pos)
    9. {
    10. QMenu *menu = new QMenu(this);
    11.  
    12. m_insererRow = menu->addAction("Inser row here");
    13.  
    14. QAction *selectedItem = menu->exec(QCursor::pos());
    15.  
    16. // Some actions...
    17. }
    To copy to clipboard, switch view to plain text mode 

    Many thanks in advance!


    Added after 54 minutes:


    Any help? Do you required more information please?
    Last edited by Stanfillirenfro; 2nd April 2014 at 11:53.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: No reaction after right clicking on the QTableWidget's headers

    You don't seem to have switched the contextMenuPolicy of the table view to CustomContextMenu

    Cheers,
    _

  5. #5
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No reaction after right clicking on the QTableWidget's headers

    Thanks Anda_Skoa!

    Of courses, I did it in the constructor of my class liste this:

    Qt Code:
    1. m_mywindow->setContextMenuPolicy(Qt::CustomContextMenu);
    To copy to clipboard, switch view to plain text mode 

    Is the constructor the wright place for that or should I do it in the method?

    Thanks in advance

  6. #6
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No reaction after right clicking on the QTableWidget's headers

    Does anyone have an idea please?

  7. #7
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: No reaction after right clicking on the QTableWidget's headers

    contextMenuRequest on headers are trigger by the QHeaderView try something adapting this :
    Qt Code:
    1. ui->tableWidget->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
    2. ui->tableWidget->verticalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
    3. connect(ui->tableWidget->horizontalHeader(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(clicked()));
    4. connect(ui->tableWidget->verticalHeader(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(clicked()));
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No reaction after right clicking on the QTableWidget's headers

    Many thanks Nix!!!

    It is working perfectly. The problem is solved.

    Many thanks one more time!

Similar Threads

  1. QTableWidget do not hide headers on resize, what to do?
    By Bong.Da.City in forum Qt Programming
    Replies: 7
    Last Post: 24th June 2012, 17:39
  2. Resizing headers view in the QTableWidget
    By jano_alex_es in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2010, 11:55
  3. QTableWidget headers
    By vieraci in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2009, 09:25
  4. Replies: 2
    Last Post: 11th March 2009, 03:00
  5. trying to union two headers of QTableWidget
    By uygar in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2007, 16:55

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.