1. 参考
# QtWidgets.pyi
class QLineEdit(PySide6.QtWidgets.QWidget):
LeadingPosition : QLineEdit.ActionPosition = ... # 0x0
TrailingPosition : QLineEdit.ActionPosition = ... # 0x1
Normal : QLineEdit.EchoMode = ... # 0x0
NoEcho : QLineEdit.EchoMode = ... # 0x1
Password : QLineEdit.EchoMode = ... # 0x2
PasswordEchoOnEdit : QLineEdit.EchoMode = ... # 0x3
class ActionPosition(Enum):
LeadingPosition : QLineEdit.ActionPosition = ... # 0x0
TrailingPosition : QLineEdit.ActionPosition = ... # 0x1
class EchoMode(Enum):
Normal : QLineEdit.EchoMode = ... # 0x0
NoEcho : QLineEdit.EchoMode = ... # 0x1
Password : QLineEdit.EchoMode = ... # 0x2
PasswordEchoOnEdit : QLineEdit.EchoMode = ... # 0x3
@overload
def __init__(self, arg__1:str, parent:Optional[PySide6.QtWidgets.QWidget]=...) -> None: ...
@overload
def __init__(self, parent:Optional[PySide6.QtWidgets.QWidget]=...) -> None: ...
@overload
def addAction(self, action:PySide6.QtGui.QAction) -> None: ...
@overload
def addAction(self, action:PySide6.QtGui.QAction, position:PySide6.QtWidgets.QLineEdit.ActionPosition) -> None: ...
@overload
def addAction(self, arg__1:PySide6.QtGui.QAction) -> None: ...
@overload
def addAction(self, icon:Union[PySide6.QtGui.QIcon, PySide6.QtGui.QPixmap], position:PySide6.QtWidgets.QLineEdit.ActionPosition) -> PySide6.QtGui.QAction: ...
def alignment(self) -> PySide6.QtCore.Qt.Alignment: ...
def backspace(self) -> None: ...
def changeEvent(self, arg__1:PySide6.QtCore.QEvent) -> None: ...
def clear(self) -> None: ...
def completer(self) -> PySide6.QtWidgets.QCompleter: ...
def contextMenuEvent(self, arg__1:PySide6.QtGui.QContextMenuEvent) -> None: ...
def copy(self) -> None: ...
def createStandardContextMenu(self) -> PySide6.QtWidgets.QMenu: ...
def cursorBackward(self, mark:bool, steps:int=...) -> None: ...
def cursorForward(self, mark:bool, steps:int=...) -> None: ...
def cursorMoveStyle(self) -> PySide6.QtCore.Qt.CursorMoveStyle: ...
def cursorPosition(self) -> int: ...
def cursorPositionAt(self, pos:PySide6.QtCore.QPoint) -> int: ...
def cursorRect(self) -> PySide6.QtCore.QRect: ...
def cursorWordBackward(self, mark:bool) -> None: ...
def cursorWordForward(self, mark:bool) -> None: ...
def cut(self) -> None: ...
def del_(self) -> None: ...
def deselect(self) -> None: ...
def displayText(self) -> str: ...
def dragEnabled(self) -> bool: ...
def dragEnterEvent(self, arg__1:PySide6.QtGui.QDragEnterEvent) -> None: ...
def dragLeaveEvent(self, e:PySide6.QtGui.QDragLeaveEvent) -> None: ...
def dragMoveEvent(self, e:PySide6.QtGui.QDragMoveEvent) -> None: ...
def dropEvent(self, arg__1:PySide6.QtGui.QDropEvent) -> None: ...
def echoMode(self) -> PySide6.QtWidgets.QLineEdit.EchoMode: ...
def end(self, mark:bool) -> None: ...
def event(self, arg__1:PySide6.QtCore.QEvent) -> bool: ...
def focusInEvent(self, arg__1:PySide6.QtGui.QFocusEvent) -> None: ...
def focusOutEvent(self, arg__1:PySide6.QtGui.QFocusEvent) -> None: ...
def hasAcceptableInput(self) -> bool: ...
def hasFrame(self) -> bool: ...
def hasSelectedText(self) -> bool: ...
def home(self, mark:bool) -> None: ...
def initStyleOption(self, option:PySide6.QtWidgets.QStyleOptionFrame) -> None: ...
def inputMask(self) -> str: ...
def inputMethodEvent(self, arg__1:PySide6.QtGui.QInputMethodEvent) -> None: ...
@overload
def inputMethodQuery(self, arg__1:PySide6.QtCore.Qt.InputMethodQuery) -> Any: ...
@overload
def inputMethodQuery(self, property:PySide6.QtCore.Qt.InputMethodQuery, argument:Any) -> Any: ...
def insert(self, arg__1:str) -> None: ...
def isClearButtonEnabled(self) -> bool: ...
def isModified(self) -> bool: ...
def isReadOnly(self) -> bool: ...
def isRedoAvailable(self) -> bool: ...
def isUndoAvailable(self) -> bool: ...
def keyPressEvent(self, arg__1:PySide6.QtGui.QKeyEvent) -> None: ...
def keyReleaseEvent(self, arg__1:PySide6.QtGui.QKeyEvent) -> None: ...
def maxLength(self) -> int: ...
def minimumSizeHint(self) -> PySide6.QtCore.QSize: ...
def mouseDoubleClickEvent(self, arg__1:PySide6.QtGui.QMouseEvent) -> None: ...
def mouseMoveEvent(self, arg__1:PySide6.QtGui.QMouseEvent) -> None: ...
def mousePressEvent(self, arg__1:PySide6.QtGui.QMouseEvent) -> None: ...
def mouseReleaseEvent(self, arg__1:PySide6.QtGui.QMouseEvent) -> None: ...
def paintEvent(self, arg__1:PySide6.QtGui.QPaintEvent) -> None: ...
def paste(self) -> None: ...
def placeholderText(self) -> str: ...
def redo(self) -> None: ...
def selectAll(self) -> None: ...
def selectedText(self) -> str: ...
def selectionEnd(self) -> int: ...
def selectionLength(self) -> int: ...
def selectionStart(self) -> int: ...
def setAlignment(self, flag:PySide6.QtCore.Qt.Alignment) -> None: ...
def setClearButtonEnabled(self, enable:bool) -> None: ...
def setCompleter(self, completer:PySide6.QtWidgets.QCompleter) -> None: ...
def setCursorMoveStyle(self, style:PySide6.QtCore.Qt.CursorMoveStyle) -> None: ...
def setCursorPosition(self, arg__1:int) -> None: ...
def setDragEnabled(self, b:bool) -> None: ...
def setEchoMode(self, arg__1:PySide6.QtWidgets.QLineEdit.EchoMode) -> None: ...
def setFrame(self, arg__1:bool) -> None: ...
def setInputMask(self, inputMask:str) -> None: ...
def setMaxLength(self, arg__1:int) -> None: ...
def setModified(self, arg__1:bool) -> None: ...
def setPlaceholderText(self, arg__1:str) -> None: ...
def setReadOnly(self, arg__1:bool) -> None: ...
def setSelection(self, arg__1:int, arg__2:int) -> None: ...
def setText(self, arg__1:str) -> None: ...
@overload
def setTextMargins(self, left:int, top:int, right:int, bottom:int) -> None: ...
@overload
def setTextMargins(self, margins:PySide6.QtCore.QMargins) -> None: ...
def setValidator(self, arg__1:PySide6.QtGui.QValidator) -> None: ...
def sizeHint(self) -> PySide6.QtCore.QSize: ...
def text(self) -> str: ...
def textMargins(self) -> PySide6.QtCore.QMargins: ...
def timerEvent(self, arg__1:PySide6.QtCore.QTimerEvent) -> None: ...
def undo(self) -> None: ...
def validator(self) -> PySide6.QtGui.QValidator: ...
2. 代码
简单使用下QLineEdit类中的方法。
方法 | 作用 |
---|---|
setReadOnly(self, arg__1:bool) | 设置只读 |
setText(self, arg__1:str) | 设置内容 |
text(self) | 获取内容 |
import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from ui_test import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.pushbuttonSlot)
self.ui.lineEdit.setReadOnly(True)
self.ui.lineEdit.setText("QLineEdit")
def pushbuttonSlot(self):
print(self.ui.lineEdit.text())
if __name__ == "__main__":
app = QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
sys.exit(app.exec())