Results 1 to 3 of 3

Thread: TableView highlight column on mouse-over

  1. #1
    Join Date
    Feb 2013
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Post TableView highlight column on mouse-over

    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...

    Qt Code:
    1. property int mouseColumn: 0
    2.  
    3. itemDelegate: Item {
    4. id: item
    5.  
    6. Rectangle {
    7. anchors.fill: parent
    8. color: "Green"
    9. visible: {
    10. // highlight the column the mouse is over
    11. if(styleData.column == tableView.mouseColumn)
    12. true
    13. else
    14. false
    15. }
    16. }
    17.  
    18. MouseArea {
    19. anchors.fill: parent
    20. hoverEnabled: true
    21. onPositionChanged: {
    22. var coordinates = item.mapToItem(tableView, mouse.x, mouse.y)
    23.  
    24. // TODO: how to find column index at coordinates, columnAt always returns -1 for some reason
    25. tableView.mouseColumn = tableView.__listView.columnAt(coordinates.x)
    26. }
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by KiNgFrUiT; 3rd December 2015 at 14:18.

  2. #2
    Join Date
    Feb 2013
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Post Re: TableView highlight column on mouse-over

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TableView highlight column on mouse-over

    Quote Originally Posted by KiNgFrUiT View Post
    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.
    styleData.column?

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 28th November 2015, 20:44
  2. Autoscroll TableView when Dragging Column
    By stefanadelbert in forum Qt Programming
    Replies: 3
    Last Post: 13th November 2012, 17:43
  3. Replies: 0
    Last Post: 18th April 2011, 15:07
  4. Tableview - Three subcolumns inside one column?
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 24th March 2010, 15:04
  5. Q3ListView highlight part of a column
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 5th May 2006, 09:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.