Results 1 to 10 of 10

Thread: QTreeView Mouse Highlighter

  1. #1
    Join Date
    Dec 2016
    Posts
    37
    Qt products
    Qt5
    Platforms
    Windows

    Default QTreeView Mouse Highlighter

    I would like to draw a vertical colored line any time the mouse is within my QTreeView.
    I thought that I could get the viewport and set mouse tracking, then draw a vertical line
    at the mouse position. But I don't see a method in QTreeView to get the viewport.

    What am I missing?

    t

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView Mouse Highlighter

    Do you mean that you want to change the mouse cursor once it is above your QTreeView?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: QTreeView Mouse Highlighter

    Quote Originally Posted by tvj4218 View Post
    But I don't see a method in QTreeView to get the viewport.

    What am I missing?
    You probably didn't look into the base classes.

    Either do that manually by following the "inherits" class links in the documentation or use the link that says "List of all members, including inherited members"

    Cheers,
    _

  4. #4
    Join Date
    Dec 2016
    Posts
    37
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView Mouse Highlighter

    ok, so I reimplement mouseMoveEvent to get the mouse coordinates.
    Then in the reimplemented paint method in my delegate, which subclasses
    one of the Qt classes, I draw a vertical line.
    The problem is, the vertical line does not move with the mouse.
    This is because I am not able to call paint as I don't have QPainter, etc.
    in my class which is subclassed from QTreeView.
    I call update instead, but it doesn't fix the problem.
    How do I fix this?

    thanks.

    n

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView Mouse Highlighter

    I am not sure about your setup but if you want a widget to update, i.e. get its paintEvent() called by Qt, then you call update() on it.

    Cheers,
    _

  6. #6
    Join Date
    Dec 2016
    Posts
    37
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView Mouse Highlighter

    ok that worked. Thank you.

    The problem I have now is that the vertical line only shows up only next to the items in the tree view.
    This is an issue because if the items only fill half the tree view, then the vertical line only covers half the screen.
    I want the line to cover the whole height of the tree view. Is there a way to get the tree size/height?

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView Mouse Highlighter

    If you want the line to go on top of all items and even empty space, you could draw it in the view's paintEvent() method.

    Or maybe on the viewport, e.g. by setting a custom widget as the viewport.

    Cheers,
    _

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView Mouse Highlighter

    I am still confused at what the OP wants, but it seems you guys do understand - could some one enlighten me please?
    To me it sounds as what he wants is to have a custom mouse pointer when over the tree view - for that there is no need to do any custom painting, just set an image to the cursor when it enters the tree view.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView Mouse Highlighter

    Quote Originally Posted by high_flyer View Post
    I am still confused at what the OP wants, but it seems you guys do understand - could some one enlighten me please?
    My interpretation is that the view should show a vertical line over its full height at the position of the mouse cursor, like a ruler or reference line.

    Cheers,
    _

  10. #10
    Join Date
    Dec 2016
    Posts
    37
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView Mouse Highlighter

    Yes,that's exactly what I mean.

Similar Threads

  1. Replies: 3
    Last Post: 23rd August 2012, 15:06
  2. xml highlighter
    By inspiron18 in forum Newbie
    Replies: 1
    Last Post: 4th March 2012, 00:48
  3. Using QtDesigner highlighter in my own application
    By elcuco in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2011, 18:59
  4. textbox+highlighter
    By nima in forum Qt Programming
    Replies: 0
    Last Post: 27th June 2011, 15:39
  5. QTextEdit with syntax highlighter
    By sarode in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2006, 07:20

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.