forked from muziing/PyQt_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-QPlainTextEdit-软换行、覆盖模式、tab控制.py
45 lines (34 loc) · 1.16 KB
/
02-QPlainTextEdit-软换行、覆盖模式、tab控制.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
from PyQt5.Qt import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QPlainTextEdit")
self.resize(500, 500)
self.move(400, 250)
self.setup_ui()
def setup_ui(self):
test_btn = QPushButton("测试按钮", self)
test_btn.move(20, 20)
pte = QPlainTextEdit(self)
pte.move(100, 100)
pte.resize(300, 300)
# --------自动换行-------------
print(pte.lineWrapMode())
pte.setLineWrapMode(QPlainTextEdit.NoWrap) # 取消自动换行
"""
NoWrap = 0
WidgetWidth = 1
"""
# ------覆盖模式-----------
print(pte.overwriteMode()) # 默认值为False
# pte.setOverwriteMode(True) # 覆盖单个字符,对中文支持不佳
# -----Tab控制-------
# pte.setTabChangesFocus(True) # 将Tab键功能改为切换焦点
pte.setTabChangesFocus(False) # 将Tab键功能改为插入制表符
pte.setTabStopDistance(100)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())