1、QTextEdit是一个高级编辑器(所见即所得),支持使用HTML样式标签的富文本格式。
from PyQt5.Qt import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QTextEdit的学习")
self.resize(500, 500)
self.setup_ui()
def setup_ui(self):
te = QTextEdit("xxxxx", self)
te.move(50, 50)
te.resize(300, 300)
te.setStyleSheet("background-color:cyan;")
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = Window()
window.resize(500, 500)
window.show()
sys.exit(app.exec_())
2、占位文本的设置:(文本框内部内容为空时给的一个提示信息)
定义一个新的占位文本提示的方法,调用该方法。
from PyQt5.Qt import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QTextEdit的学习")
self.resize(500, 500)
self.setup_ui()
def setup_ui(self):
te = QTextEdit("xxxxx", self)
self.te = te
te.move(50, 50)
te.resize(300, 300)
te.setStyleSheet("background-color:cyan;")
# 调用占位文本提示的方法
self.占位文本的提示()
def 占位文本的提示(self):
self.te.setPlaceholderText("请输入你的个人简历")
print(self.te.placeholderText())
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = Window()
window.resize(500, 500)
window.show()
sys.exit(app.exec_())