Results 1 to 5 of 5

Thread: Get last event in QTreeWidget

  1. #1
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Get last event in QTreeWidget

    I wonder if the last event was Qt::RightButton. For QTreeWiget.

    My code:
    Qt Code:
    1. void vf_rfid::on_treeWidget_itemClicked(QTreeWidgetItem* item, int column)
    2. {
    3. if(item->childCount()==0){
    4. QMenu menu(ui->treeWidget);
    5. QAction *action = menu.addAction("Remover");
    6. QObject::connect(action,SIGNAL(triggered()),this,SLOT(teste()));
    7. menu.exec(ui->treeWidget->mapToParent(QCursor::pos()));
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    But I want it up only occurs with right click event.

    I found:
    http://developer.qt.nokia.com/faq/an..._a_qtreewidget
    great tutorial,
    But I do not want to create another class TreeWidget.

  2. #2
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get last event in QTreeWidget

    Hi,

    Try using QTreeWidget::customContextMenuRequested(QPoint pos), and use the QTreeWidget::itemAt(QPoint&) to find the item. If that returns 0, just skip the menu...
    You will need to change the contextMenuPolicy of the tree widget...

    Hth.

  3. #3
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get last event in QTreeWidget

    Ok, it worked.

    Thank you.

    Was inserted in the main: ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);

    Qt Code:
    1. void vf_rfid::on_treeWidget_customContextMenuRequested(QPoint pos)
    2. {
    3. QMenu menu(ui->treeWidget);
    4. selT = ui->treeWidget->currentIndex().row();
    5.  
    6. ...
    7. QAction *desativar = menu.addAction("Desativar");
    8. QObject::connect(desativar,SIGNAL(triggered()),this,SLOT(desativarT()));
    9. ...
    10.  
    11. menu.addSeparator();
    12. QAction *remover = menu.addAction("Remover");
    13. QObject::connect(remover,SIGNAL(triggered()),this,SLOT(removerT()));
    14.  
    15. menu.exec(ui->treeWidget->mapToParent(QCursor::pos()));
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get last event in QTreeWidget

    Mano,

    Use the pos you receive by parameter... QCursor::pos() may be other, if you have a queued connection.
    And more, why don't you leave the menu created, and just QMenu::popup(pos)?
    This way you will not need to create the actions and connect them every time the user right-click the item...


  5. #5
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Get last event in QTreeWidget

    Hi,

    I'm not using the "pos" because it's not located where the cursor is positioned.
    I did not know of the popup. I will use it.
    Thanks for the tip.

Similar Threads

  1. QTreeWidget Horizontal header double click event???
    By deepal_de in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2011, 08:31
  2. qtreewidget and drop event detection
    By eric_vi in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2010, 11:20
  3. Replies: 10
    Last Post: 15th January 2010, 14:35
  4. Replies: 0
    Last Post: 23rd October 2008, 12:43
  5. Replies: 2
    Last Post: 17th March 2008, 12:53

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.