0
点赞
收藏
分享

微信扫一扫

PyQT QLineEdit

kiliwalk 2022-03-14 阅读 103
from PyQt5.Qt import *
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QLineEdit..")
        self.resize(500, 400)
        self.setup_ui()
    def setup_ui(self):
        ql_a = QLineEdit(self)
        ql_a.setPlaceholderText("Text...")
        action = QAction(self)
        action.setIcon(QIcon("xxx.png"))
        ql_a.addAction(action, QLineEdit.TrailingPosition)
        ql_a.setEchoMode(QLineEdit.Password)
        ql_a.move(100, 100)

        ql_b = QLineEdit(self)
        ql_b.move(100, 150)

        btn = QPushButton(self)
        btn.setText('copy')
        btn.move(100, 200)

        btn1 = QPushButton(self)
        btn1.setText('cancel')
        btn1.move(200, 200)
        def cancel():
            ql_a.deselect()
        btn1.clicked.connect(cancel)

        def copy():
            text = ql_a.text()
            print(text)
            ql_a.setSelection(0, len(text))
            ql_b.setText(text)
        btn.clicked.connect(copy)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
举报

相关推荐

0 条评论