pyside6界面开发笔记(07)

程序入口模板:pyside6界面开发笔记——模板框架
回顾:
标签控件
信号与槽
消息框控件

文本框控件

单行文本框

class Window(QWidget):

    def __init__(self):
        super(Window,self).__init__()

        self.username_line=QLineEdit()
        self.password_line=QLineEdit()

        h_layout1=QHBoxLayout()
        h_layout2=QHBoxLayout()
        v_layout=QVBoxLayout()

        h_layout1.addWidget(QLabel("用户名:"))
        h_layout1.addWidget(self.username_line)
        h_layout2.addWidget(QLabel("密码:"))
        h_layout2.addWidget(self.password_line)

        v_layout.addLayout(h_layout1)
        v_layout.addLayout(h_layout2)
        self.setLayout(v_layout)

QLineEdit内容显示的四种模式:

QLineEdit.Normal:默认

QLineEdit.NoEcho:不显示输入内容

QLineEdit.Password:密文

QLineEdit.PasswordEchoOnEdit:密文,输入时明文,完毕后密文

QLineEdit常用方法:

text():获取文本

setMaxLength():设置允许的最大字符

setReadOnly():设置只读

setText():设置文本

setTextMargins():设置左上右下边距

文字编辑框

class Window(QWidget):

    def __init__(self):
        super(Window,self).__init__()

        self.edit=QTextEdit()

        h_layout=QHBoxLayout()
        h_layout.addWidget(self.edit)
        self.setLayout(h_layout)

关闭自动换行

class Window(QWidget):

 def __init__(self):
     super(Window,self).__init__()

     self.edit=QTextEdit()

     self.edit.setLineWrapMode(QTextEdit.NoWrap)

     h_layout=QHBoxLayout()
     h_layout.addWidget(self.edit)
     self.setLayout(h_layout)
  • QTextEdit常用方法
方法描述
toHtml()html格式返回
toMarkDown()markdown格式返回
toPlainText()纯文本
setReadOnly()设置只读
setHtml传入html,显示在QTextEdit上
toMarkDown()传入markdown,显示在QTextEdit上
toPlainText()传入纯文本,显示在QTextEdit上

文本浏览框

本质是只读模式下的QTextEdit()

class Window(QWidget):

    def __init__(self):
        super(Window,self).__init__()

        self.browser=QTextBrowser()
        self.button=QPushButton('新增一行')
        self.button.clicked.connect(self.append_text)

        v_layout=QVBoxLayout()
        v_layout.addWidget(self.browser)
        v_layout.addWidget(self.button)
        self.setLayout(v_layout)

    def append_text(self):
        self.browser.append('+1')

Pyside6学习笔记,笔记笔者根据《Pyqt编程快速上手》将其中pyqt改为pyside整理而成,所有代码均经过验证

  • 27
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值