代码拉取完成,页面将自动刷新
import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *
class Demo(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
layout = QVBoxLayout()
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
toolBar =QToolBar()
cb = QCheckBox('IsReadOnly')
cb.stateChanged.connect(self.OnIsReadOnlyChanged)
toolBar.addWidget(cb)
cb = QCheckBox('ClearButtonEnable')
cb.stateChanged.connect(self.OnClearButtonEnableChanged)
toolBar.addWidget(cb)
toolBar.addWidget(QLabel('Alignment:'))
alignment = QComboBox()
alignment.addItems(Qt.AlignmentFlag.__members__.keys())
alignment.currentTextChanged.connect(self.AlignmentChanged)
toolBar.addWidget(alignment)
toolBar.addWidget(QLabel('EchoMode:'))
EchoMode = QComboBox()
EchoMode.addItems(QLineEdit.EchoMode.__members__.keys())
EchoMode.currentTextChanged.connect(self.EchoModeChanged)
toolBar.addWidget(EchoMode)
toolBar.addWidget(QLabel('PlaceholderText:'))
self.placeholder = QLineEdit()
self.placeholder.editingFinished.connect(self.SetPlaceholderText)
toolBar.addWidget(self.placeholder)
toolBar.addWidget(QLabel('InputMask:'))
self.inputMask = QLineEdit()
self.inputMask.editingFinished.connect(self.SetInputMask)
toolBar.addWidget(self.inputMask)
toolBar.addWidget(QLabel('MaxLength:'))
self.maxlength = QLineEdit()
intValidator=QIntValidator()
intValidator.setRange(1,65536)
self.maxlength.setValidator(intValidator)
self.maxlength.editingFinished.connect(self.SetMaxLength)
toolBar.addWidget(self.maxlength)
toolBar1=QToolBar()
btn = QPushButton('Add Action')
btn.clicked.connect(self.AddAction)
toolBar1.addWidget(btn)
btn = QPushButton('Remove Cursor')
btn.setToolTip('Move one cursor to the right')
btn.clicked.connect(self.RemoveCursor)
toolBar1.addWidget(btn)
layout.addWidget(toolBar)
layout.addWidget(toolBar1)
self.lineEdit = QLineEdit()
layout.addWidget(self.lineEdit)
group=QGroupBox('LineEdit with IntValidator(10~100)')
groupLayout=QVBoxLayout()
edit=QLineEdit()
intValidator=QIntValidator()
intValidator.setRange(10,100)
edit.setValidator(intValidator)
groupLayout.addWidget(edit)
group.setLayout(groupLayout)
layout.addWidget(group)
group=QGroupBox('LineEdit with DoubleValidator(10~50)')
groupLayout=QVBoxLayout()
edit=QLineEdit()
doubleValidator=QDoubleValidator()
doubleValidator.setRange(10,50)
doubleValidator.setDecimals(2)
edit.setValidator(doubleValidator)
groupLayout.addWidget(edit)
group.setLayout(groupLayout)
layout.addWidget(group)
group=QGroupBox('LineEdit with RegularValidator')
groupLayout=QVBoxLayout()
edit=QLineEdit()
validator=QRegularExpressionValidator()
validator.setRegularExpression(QRegularExpression('[a-zA-Z0-9]+$'))
edit.setValidator(validator)
groupLayout.addWidget(edit)
group.setLayout(groupLayout)
layout.addWidget(group)
self.setLayout(layout)
def OnClearButtonEnableChanged(self,state):
self.lineEdit.setClearButtonEnabled(state)
self.parent.OnShowMessage(f"Set ClearButtonEnabled={state}")
def OnIsReadOnlyChanged(self,state):
self.lineEdit.setReadOnly(state)
self.parent.OnShowMessage(f"Set ReadOnly={state}")
def AlignmentChanged(self,text):
alignment = Qt.AlignmentFlag[text]
self.lineEdit.setAlignment(alignment)
self.parent.OnShowMessage(f'Set Alignment: {alignment}')
def EchoModeChanged(self,text):
mode = QLineEdit.EchoMode[text]
self.lineEdit.setEchoMode(mode)
self.parent.OnShowMessage(f'Set EchoMode: {mode}')
def SetPlaceholderText(self):
placeholder = self.placeholder.text()
self.lineEdit.setPlaceholderText(placeholder)
self.parent.OnShowMessage(f'Set PlaceholderText: {placeholder}')
def SetInputMask(self):
inputMask = self.inputMask.text()
self.lineEdit.setInputMask(inputMask)
self.parent.OnShowMessage(f'Set InputMask: {inputMask}')
def SetMaxLength(self):
length=int(self.maxlength.text())
self.lineEdit.setMaxLength(length)
self.parent.OnShowMessage(f'Set MaxLength: {length}')
def AddAction(self):
action = QAction(f'Action{len(self.lineEdit.actions())}',self.lineEdit)
action.setIcon(QIcon(f'{self.parent.getAppDir()}/resources/confirm.png'))
self.lineEdit.addAction(action,QLineEdit.ActionPosition.TrailingPosition)
self.parent.OnShowMessage(f'Add Action: {action.text()}')
def RemoveCursor(self):
self.lineEdit.cursorForward(True,1)
self.parent.OnShowMessage(f'Current Cursor: {self.cursorPosition()}')
def runDemo(parent):
wigdet = Demo(parent)
return wigdet
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。