Get last event in QTreeWidget
I wonder if the last event was Qt::RightButton. For QTreeWiget.
My code:
Code:
{
if(item->childCount()==0){
QMenu menu
(ui
->treeWidget
);
QAction *action
= menu.
addAction("Remover");
QObject::connect(action,
SIGNAL(triggered
()),
this,
SLOT(teste
()));
menu.
exec(ui
->treeWidget
->mapToParent
(QCursor::pos()));
}
}
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.
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.
Re: Get last event in QTreeWidget
Ok, it worked.
Thank you.
Was inserted in the main: ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
Code:
void vf_rfid
::on_treeWidget_customContextMenuRequested(QPoint pos
) {
QMenu menu
(ui
->treeWidget
);
selT = ui->treeWidget->currentIndex().row();
...
QAction *desativar
= menu.
addAction("Desativar");
QObject::connect(desativar,
SIGNAL(triggered
()),
this,
SLOT(desativarT
()));
...
menu.addSeparator();
QAction *remover
= menu.
addAction("Remover");
QObject::connect(remover,
SIGNAL(triggered
()),
this,
SLOT(removerT
()));
menu.
exec(ui
->treeWidget
->mapToParent
(QCursor::pos()));
}
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...
;)
Re: Get last event in QTreeWidget
Hi,
I'm not using the "pos" because it's not located where the cursor is positioned. :confused:
I did not know of the popup. I will use it.
Thanks for the tip.