您需要确保有QLineEdit
背景文本,并且在其上面打印了新的文本。我用过placeholderText()
,但是文字消失了。
我想创建一个自定义的 LineEdit,继承自QLineEdit
,但我什至不知道从哪里开始。
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from sys import argv, exit
class LineEdit(QLineEdit):
def __init__(self, *args, **kwargs):
QLineEdit.__init__(self, *args, **kwargs)
class Window(QMainWindow):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.setWindowTitle('LineEdit')
self.setMinimumSize(640, 480)
self.resize(640, 480)
self.centralwidget = QWidget(self)
self.centralwidget.setObjectName(u"centralwidget")
self.verticalLayout = QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(u"verticalLayout")
lineedit = LineEdit('', self)
self.verticalLayout.addWidget(lineedit)
self.setCentralWidget(self.centralwidget)
if __name__ == "__main__":
app = QApplication(argv)
window = Window()
window.show()
exit(app.exec())
或者,
QLineEdit
在布局管理器中将不同的放置在彼此的顶部QGridLayout
。安装您的导入并尝试: