TreeView - Context menu
-
wrote on 12 Sept 2013, 18:21 last edited by
I'm using Qt 5.1.1's Desktop controls. I need to be able to do a context menu on a selected row in the TableView.
I looked into "clicked" and "activated" signals but they don't provide which mouse button was pressed. Any ideas?
Thanks
-Atif -
wrote on 21 Sept 2013, 19:33 last edited by
First Create Actions in you application UI. Then for your TreeView Widget, use setContextMenuPolicy(Qt::ActionsContextMenu); In your constructor, assign those actions to your Widget with ui->tableWidget->addAction(ui->actionNew);
-
wrote on 23 Sept 2013, 14:54 last edited by
Your title is a bit misleading as it refers to TableView.
There are two ways to achieve this:
@ TableView {
id: table
anchors.fill: parent
model: 100
TableViewColumn { title: "First" }
MouseArea {
id: mouse
acceptedButtons: Qt.RightButton
anchors.fill: parent
onClicked: menu.popup()
Menu { id: menu ; MenuItem { text: "Popup at row " + table.rowAt(mouse.mouseX, mouse.mouseY) } }
}
}
@
Alternatively you can set a custom itemDelegate and place the menu in there.