简体   繁体   中英

Automatic focus on showing deletes the placeholder text of a QLineEdit

I use PyQt4 and Python 2.7.9.

My program contains a few QLineEdit objects. The problem is that when the program is launched, one of the QLineEdits is being focused automatically, which causes my placeholder text to disappear.

Is there any way to prevent it, or at least don't let it hide the placeholder text?

Another way is

self.this_widget.clearFocus()

after window has been shown. Only in Qt5 placeholder texts are displayed even with focus. So maybe switch to PyQt5.

You can use setFocus to put the focus on a different widget (although, depending on which widget you pick, you might also need to set the focus-policy first):

    self.some_other_widget.setFocusPolicy(QtCore.Qt.TabFocus)
    self.some_other_widget.setFocus()

Alternatively, if you use Qt Designer to create the GUI, you could edit the tab-order so that the line-edit is not the first in the chain. This can also be done programmatically using QWidget.setTabOrder .

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