Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TreeView - Context menu
Forum Update on Monday, May 27th 2025

TreeView - Context menu

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    atif1996
    wrote on 12 Sept 2013, 18:21 last edited by
    #1

    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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blueshift
      wrote on 21 Sept 2013, 19:33 last edited by
      #2

      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);

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on 23 Sept 2013, 14:54 last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved