[Qt-interest] QLineEdit loosing its selection

Oliver Demetz forenbeitraege at oliverdemetz.de
Tue Aug 4 08:40:16 CEST 2009


Daniel Vérité schrieb:
> 	 Oliver Demetz writes
> 
>> Well, the thing is that as soon as (any) other widget is clicked, the 
> 
>> selection is removed.
>> So, at the moment the widget gets a mouse down event and I could 
> react, 
>> the selection *is already gone*.
>> The mechanism is built deep into Qt and I don't know how to disable 
> it.
> 
> You might need to mimic the way QCompleter works: it installs an 
> eventfilter for both widgets (the lineedit and the popup), with some 
> hack to avoid the problem of the lost focus, as well as an 
> event-routing logic. 

Yes! I am searching for this hack.

The result is that you can still type in the
> lineedit while the popup is shown, which seems a bit like the problem 
> you're trying to solve. I doubt the selection gets lost in this case.
> 
No!
This problem is solved by overriding the protected functions

VirtualKeyboard::keyPressEvent(QKeyEvent * event)
and
VirtualKeyboard::keyReleaseEvent(QKeyEvent * event)

and duplicating the received key events there.

> Or maybe you could just use setFocusProxy() if it works for you, but my 
> own experience with it was not conclusive at all.
> 
For me also this did not work, but as said, the typing is not my problem.



> Best regards,

Best regards,
Oliver




More information about the Qt-interest-old mailing list