PyQt5 common methods of a text box control QLineEdit

In this paper, a note of a single text box control QLineEdit () use some of the methods of the class and each method and problems encountered, from time to time update! ! !

1、setPlaceholderText()与setText()

Two methods are possible to set the text content of the text box, but the effect is not the same, it is the first significant floating text, more like a default prompts, the second is the way normal display and manual input ! Use of the following effects:

lineE1 = QLineEdit(self)
lineE2 = QLineEdit(self)
lineE1.setPlaceholderText("请输入文本!")
lineE2.setText("请输入文本!")

Here Insert Picture Description
Another point is more important difference is that, with setPlaceholderText () method to display the text can not return, text () method can only return setText () to set up and manually enter the text, verify the following:

text1 = lineE1.text()
text2 = lineE2.text()
print("text1:"+text1)
print("text2:"+text2)

Here Insert Picture Description
So I want to return to the text you need to pay attention to the method call chatter!

2、setReadOnly()

This method is mainly to set read-only text boxes that can be edited. Easy to understand, but need to add brackets kinds bool variable, True / False, as shown below, the second text box setReadOnly () is set to True can not be edited after it!

lineE2.setReadOnly(True)

Here Insert Picture Description

Published 17 original articles · won praise 3 · Views 1803

Guess you like

Origin blog.csdn.net/weixin_43350361/article/details/104888461