pyqt5标签中的字设置不同字体_PyQt5控件字体样式等设置的
实现
⼀、API接⼝设置
⽐如我这段代码中的⼀些设置,设置⽂字、居中、禁⽌复制、LineEdit输⼊为password等等
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QFrame
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtWidgets import QSizePolicy
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QGridLayout
from PyQt5.QtWidgets import QApplication
from View import interface
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow,self).__init__(None)
self.setWindowTitle("对⾦属腐蚀性试验仪")
self.initUI()
def initUI(self):
layout = QGridLayout()
layout.setSpacing(10)
self.loginLabel = QLabel("⽤户名:")
self.loginLabel.setAlignment(Qt.AlignRight)
self.loginLabel.setStyleSheet("color:rgb(20,20,20,255);font-size:16px;font-weight:bold:text")
self.loginTxt = QLineEdit()
self.loginTxt.setText("admin")
self.loginTxt.setPlaceholderText("User Name")
self.loginTxt.setClearButtonEnabled(True)
self.pwdLabel = QLabel("密码:")
self.pwdLabel.setAlignment(Qt.AlignRight)
self.pwdTxt = QLineEdit()
self.pwdTxt.setContextMenuPolicy(Qt.NoContextMenu) #禁⽌复制粘贴
self.pwdTxt.setPlaceholderText("Password")
self.pwdTxt.setText("admin")
self.pwdTxt.setEchoMode(QLineEdit.Password)
self.pwdTxt.setClearButtonEnabled(True)
self.loginBtn = QPushButton("登陆")
self.headLabel = QLabel("⽤户登陆")
size(300,30)
self.headLabel.setAlignment(Qt.AlignCenter)
self.headLabel.setStyleSheet("color:rgb(10,10,10,255);font-size:25px;font-weight:bold;font-family:Roman times;") self.headLabel.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
layout.addWidget(self.headLabel,0,0,1,2)
policy = self.headLabel.sizePolicy()
print(policy.verticalPolicy())
policy.setVerticalPolicy(1)
print(policy.verticalPolicy())
# policy.setVerticalPolicy(1)
layout.addWidget(self.loginLabel,1,0)
layout.addWidget(self.loginTxt,1,1)
layout.addWidget(self.pwdLabel,2,0)
layout.addWidget(self.pwdTxt,2,1)
layout.isteredBtn,3,0)
layout.addWidget(self.loginBtn,3,1)
frame = QFrame(self)
frame.setLayout(layout)
self.setCentralWidget(frame)
if __name__ == '__main__':
text align centerapp = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
mainWindow.activateWindow()
mainWindow.raise_()
<_()
del mainWindow
del app
1.1.0 QLineEdit⼀些属性
inputMask设置掩码
text 设置⽂本
maxLength⽂本框输⼊的最⼤字符数
frame 设置边框
echoMode 设置⽂本框显⽰格式
Normal正常显⽰所输⼊的字符,此为默认选项
NoEcho不显⽰任何输⼊的字符,常⽤于密码类型的输⼊,且长度保密Password显⽰与平台相关的密码掩饰字符,⽽不是实际输⼊的字符PasswordEchoOnEdit在编辑时显⽰字符,负责显⽰密码类型的输⼊cursorPosition光标位置
alignment⽂本对齐⽅式
AlignLeft左对齐
AlignRight右对齐
AlignCenter⽔平居中对齐
AlignJustify⽔平⽅向调整间距两端对齐
AlignTop垂直上对齐
AlignBottom垂直⽅下对齐
AlignVCenter垂直⽅向居中对齐
dragEnabled设置⽂本框是否接受拖动
readOnly设置⽂本为只读
placeholderText设置⽂本框提⽰⽂字
cursorMoveStyle光标移动风格
LogicalMoveStyle逻辑风格
VisualMoveStyle视觉风格
clearButtonEnabled快速删除按钮
参考⽂章,QLineEdit属性、信号、⽅法等
1.1 常⽤的⼀些设置
参数
作⽤
AlignAbsolute=16
AlignBaseline=256
AlignBottom=64
底端对齐
AlignCenter=132
完全居中
AlignHCenter=4
⽔平居中
AlignHorizontal_Mask=31
AlignJustify=8
可⽤空间对齐
AlignLeading=1
领头对齐(理解为左对齐吧)
AlignLeft=1
左对齐
AlignRight=2
右对齐
AlignTop=32
上对齐
AlignTrailing=2
尾对齐(右对齐
AlignVCenter=128
垂直居中
setClearButtonEnabled(self, bool): 是否有清除⽂本按钮(如我第⼀段程序⽂本框后的 ⼩⿊X) setCompleter(self, QCompleter):设置⾃动补全QLineEdit⾃动补全
setCursorMoveStyle(self, Qt_CursorMoveStyle):
setCursorPosition(self, p_int):
setDragEnabled(self, bool):
setEchoMode(self, QLineEdit_EchoMode):
setFrame(self, bool):
setInputMask(self, p_str):
setMaxLength(self, p_int):
setModified(self, bool):
setPlaceholderText(self, p_str):
setReadOnly(self, bool):
setSelection(self, p_int, p_int_1):
setText(self, p_str):
setTextMargins(self, *__args):
setValidator(self, QValidator):
到此这篇关于PyQt5 控件字体样式等设置的实现的⽂章就介绍到这了,更多相关PyQt5 控件字体样式内容请搜索聚⽶学院以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持聚⽶学院!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。