[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] QTextEdit and clickable links
From:       Sundance <sundance () ierne ! eu ! org>
Date:       2003-09-29 14:04:56
[Download RAW message or body]

I heard Sundance said:

> Is there any way to do it that I may not be aware of?

Okay, found it. Here's how I did, as a reference in case someone else 
has the same problem later on. :)

The standard behavior of a QTextEdit's content widget (that you obtain 
with the viewport() method), is to have mouseTracking enabled. This is 
because QTextEdit is a specialisation of QScrollView. There is thus an 
event sent everytime the mouse cursor moves over the QTextEdit. This 
event can be caught by overloading contentsMouseMoveEvent().

In there, you get the current position of the mouse pointer, and see if 
there's a link at this position with QTextEdit's anchorAt method. This 
allows you to set the mouse cursor to a pointing hand when you're on a 
link. Be sure to set the mouse cursor for the viewport() and not the 
QTextEdit itself, since it's in the content, in the viewport(), that 
you want it to happen.

And catching clicks is, likewise, a matter of overloading 
contentsMousePressEvent() and contentsMouseReleaseEvent(). Don't forget 
to forward the event to the parent class when you're done with it!

That's it. I feared overloading a MouseMove event in Python would be 
awfully slow, but it seems to work fine.

Aaand now, for bonus points, any idea about how to make links underlined 
only when the mouse pointer is over it?

-- S.

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic