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 highlight column on mouse-over
Forum Updated to NodeBB v4.3 + New Features

TableView highlight column on mouse-over

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
tableviewcolumnathighlightmouse
2 Posts 1 Posters 2.5k 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.
  • K Offline
    K Offline
    KiNgFrUiT
    wrote on last edited by KiNgFrUiT
    #1

    I have a TableView and would like to highlight the column that the mouse is over.
    I can do the visual part by drawing a rectangle in the itemDelegate.

    What I am struggling with is getting the column index the mouse is over.
    I found the function tableView.__listView.columnAt() but it always returns -1

    Here is the relevant part of my tableView qml...

    property int mouseColumn: 0
    
    itemDelegate: Item {
    	 id: item
    
    	 Rectangle {
    		  anchors.fill: parent
    		  color: "Green"
    		  visible: {
    		      // highlight the column the mouse is over
    				if(styleData.column == tableView.mouseColumn)
    					 true
    				else
    					 false
    		  }
    	 }
    				
    	MouseArea {
    		anchors.fill: parent
    		hoverEnabled: true
    		onPositionChanged: {
    			var coordinates = item.mapToItem(tableView, mouse.x, mouse.y)
    
    			// TODO: how to find column index at coordinates, columnAt always returns -1 for some reason
    			tableView.mouseColumn = tableView.__listView.columnAt(coordinates.x)
    		}
    	}
    }
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      KiNgFrUiT
      wrote on last edited by
      #2

      Ive been looking into this a bit more myself and ive found that the TableView headerVisible property makes a big difference. I am currently hiding the header.

      When headerVisible=false then tableView.__listView.columnAt(x) always returns -1.

      When headerVisible=true then tableView.__listView.columnAt(x) works correctly.

      Id like to keep the table's header hidden if possible, hopefully a workaround for tableView.__listView.columnAt(x) is possible.

      Also, im on Windows with Qt5.5.1 mingw if that makes any difference.

      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