简体   繁体   English

如何在 pyqt5 Python 的行编辑中添加背景文本

[英]How to add background text in line edit in pyqt5 Python

I am working on a python project which includes pyqt5 .我正在研究一个python项目,其中包括pyqt5 I am using qt designer to design UI and then writing all of its code.我正在使用qt designer器来设计 UI,然后编写其所有代码。 I have a sign in page where user will enter the username and password .我有一个sign in其中输入usernamepassword It looks like below:如下所示:

在此处输入图像描述

There are two line edit in the above photo.上图中有两行编辑。 First line edit is for username and second line edit is for password.第一行编辑用于用户名,第二行编辑用于密码。 I don't want to put labels along side line edit to tell user that this is where username is written and same for password.我不想将标签放在旁边的行编辑中以告诉用户这是写入用户名的位置,并且与密码相同。 I want to put a background text in first line edit as username and in second as password, so that anyone using it know where to enter username and password.我想在第一行编辑中将背景文本作为用户名,在第二行作为密码,以便使用它的任何人都知道在哪里输入用户名和密码。 That background text will automatically remove once user starts typing in the line edit.一旦用户开始在行编辑中输入,该背景文本将自动删除。

I am not sure if that thing is called background text or something else as I am a bit weak in UI.我不确定那个东西是叫背景文本还是其他东西,因为我的 UI 有点弱。 Can anyone please tell me how can I do this.谁能告诉我我该怎么做。 Thanks谢谢

That property is called placeholderText , if you want to use it in Qt Designer then click on the QLineEdit and in the Property Editor you will find it.该属性称为placeholderText ,如果您想在 Qt 设计器中使用它,然后单击 QLineEdit 并在属性编辑器中找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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