Results 1 to 3 of 3

Thread: QTreeWidget and customContextMenuRequested

  1. #1
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidget and customContextMenuRequested

    I'm trying to create a custom popup menu in a tree widget depending on what item was right-clicked. However currently I'm stuck because the signal customContextMenuRequested seems not to get fired. Is there something else besides setContextMenuPolicy to make the signal work?

    Qt Code:
    1. AMainView::AMainView(QWidget *parent) : QMainWindow(parent)
    2. {
    3. ....
    4. iTree = new QTreeWidget();
    5. iTree->setColumnCount(1);
    6. iTree->setContextMenuPolicy(Qt::CustomContextMenu);
    7. iTree->header()->hide();
    8. connect(
    9. iTree, SIGNAL(customContextMenuRequested(const QPoint& aPosition)),
    10. this, SLOT(treeContextMenu(const QPoint& aPosition))
    11. );
    12. ....
    13. }
    14.  
    15. // declared under public slots in amainview.h:
    16. void AMainView::treeContextMenu(const QPoint& aPosition)
    17. {
    18. QMessageBox::warning(
    19. this, windowTitle(),
    20. QString().sprintf("x=%d y=%d", aPosition.x(), aPosition.y())
    21. );
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and customContextMenuRequested

    Quote Originally Posted by seneca
    Qt Code:
    1. connect(
    2. iTree, SIGNAL(customContextMenuRequested(const QPoint& aPosition)),
    3. this, SLOT(treeContextMenu(const QPoint& aPosition))
    4. );
    To copy to clipboard, switch view to plain text mode 
    You can't put parameter names in SLOT and SIGNAL macros.

    This should be:
    Qt Code:
    1. connect( iTree, SIGNAL( customContextMenuRequested( const QPoint& ) ),
    2. this, SLOT( treeContextMenu( const QPoint& ) ) );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget and customContextMenuRequested

    Thanks jacek, I figured out that this here works perfectly:

    Qt Code:
    1. connect(
    2. iTree, SIGNAL(customContextMenuRequested(QPoint)),
    3. this, SLOT(treeContextMenu(QPoint))
    4. );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  2. QTreeWidget Drag and Drop
    By tommydent in forum Qt Programming
    Replies: 10
    Last Post: 25th August 2008, 15:25
  3. Having trouble clearing a QTreeWidget.
    By Nyphel in forum Qt Programming
    Replies: 28
    Last Post: 10th October 2007, 15:33
  4. how to add icons to QTreeWidget?
    By wei243 in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2007, 08:34
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.