PDA

View Full Version : QTreeView Mouse Highlighter



tvj4218
7th February 2017, 20:06
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

high_flyer
8th February 2017, 00:43
Do you mean that you want to change the mouse cursor once it is above your QTreeView?

anda_skoa
8th February 2017, 09:06
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,
_

tvj4218
9th February 2017, 02:38
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

anda_skoa
9th February 2017, 09:01
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,
_

tvj4218
12th February 2017, 12:16
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?

anda_skoa
13th February 2017, 08:39
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,
_

high_flyer
13th February 2017, 12:35
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.

anda_skoa
14th February 2017, 09:12
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,
_

tvj4218
14th February 2017, 16:20
Yes,that's exactly what I mean.