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. TableView rowDelegate highlight problem
Forum Updated to NodeBB v4.3 + New Features

TableView rowDelegate highlight problem

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.0k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Ralf_Sonnenbaum
    wrote on last edited by
    #1

    Hello!

    I would like to have a TableView which can show a contextMenu if the user clicks the right mouse button on an item. So I wrote my own rowDelegate with a MouseArea. Selecting and showing the menu works fine, but the highlighting does not change if I select another item. What I mean is this: I select the first item in the TableView. The item is highlighted and everything is fine. But then I select a second item and the highlight of the first item stays, so both items are highlighted (but only one item is selected). I have spent a surprising amount of time on this, at least so it seems, simple problem. What am I doing wrong? Thank you for your help.

    @TableView {
    id: tableView

    anchors.fill: parent
    anchors.margins: 2
    frameVisible: false
    alternatingRowColors: false
    backgroundVisible: false

    model: myModel

    TableViewColumn {
    role: "name"
    title: qsTr("Name")
    }
    TableViewColumn {
    role: "value"
    title: qsTr("Value")
    }
    rowDelegate: Rectangle {
    width: tableView.width
    color: styleData.selected ? "blue" : "transparent"

    MouseArea {
      propagateComposedEvents: true
      anchors.fill: parent
      acceptedButtons: Qt.LeftButton | Qt.RightButton
      onClicked: (mouse.button === Qt.RightButton) ? contextMenu.popup() :  tableView.selection.select(styleData.row)
    }
    

    }
    }@

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Ralf_Sonnenbaum
      wrote on last edited by
      #2

      Well, it turned out it was a simple problem after all. You have to call selection.clear() before calling selection.select.

      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