k dev
k dev

Reputation: 55

How to handle right button clicks in QTreeWidgetItem?

I'm implementing something similar to Eclipse's Package Explorer, using QTreeWidget, but I don't know how to handle right mouse button clicks.

How do I use Qt creator so I can handle right clicks on a QTreeWidgetItem?

Upvotes: 1

Views: 675

Answers (1)

IsakBosman
IsakBosman

Reputation: 1533

You can set the context menu policy on the tree view item and then create a signal/slot event handlers as per usual.

For an example you can refer to this:

ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);

connect(ui->treeView, SIGNAL(customContextMenuRequested(const QPoint &)),
        this, SLOT(onCustomContextMenu(const QPoint &)));

Then just implement the onContextMenu function above

Upvotes: 3

Related Questions