简体   繁体   中英

PyQt5 - two blinking cursors at the same time

This is an interesting symptom:

Two different QLineEdit fields in the same dialog both have blinking cursors at the same time when the dialog itself has focus.

video

(The goal is to stop the blinking in the field that does not have focus, as it leads to user confusion and potential user error.)

When you select a different window (ie remove focus from the dialog in question), one of the fields still has a blinking cursor.

When you activate that dialog again, both fields blink again.

If you left-click in either field, the blinking cursor stops in the other field, as expected.

The focus (ie the field that captures keyboard input) seems to behave as you would expect, ie only one field receives keyboard input at a time.

The tab sequence works as expected.

This was built in QtDesigner but heavily modified in downstream code. Any ideas how this could happen?

Some similar questions talk about the dialog having its own event loop or something to that effect?

Stumbled upon this solution by trial and error: just 'burp' the focus, ie set it to the one you don't want to blink (messageField in this case), then set it to the one you do want to blink (teamField):

self.newEntryWidget.ui.messageField.setFocus()
self.newEntryWidget.ui.teamField.setFocus()

I'm not sure why this happens but it does seem to work. Hopefully someone else will find this useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM