当前位置: 首页 > news >正文

徐州网站平台漳州正规网站建设公司

徐州网站平台,漳州正规网站建设公司,dw做网站小技巧,安徽网站搭建Pyside6 QTextEdit QTextEdit使用QTextEdit常用函数文本编辑类函数文本框格式设置函数设置文字颜色设置文字背景颜色设置文字格式设置文本框样式程序设置界面设置 QTextEdit信号textChanged信号 完整程序界面程序主程序 QTextEdit类提供了一个用于编辑和显示纯文本和富文本的组… Pyside6 QTextEdit QTextEdit使用QTextEdit常用函数文本编辑类函数文本框格式设置函数设置文字颜色设置文字背景颜色设置文字格式设置文本框样式程序设置界面设置 QTextEdit信号textChanged信号 完整程序界面程序主程序 QTextEdit类提供了一个用于编辑和显示纯文本和富文本的组件更多关于QTextEdit的使用可以参考下面的文档 https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QTextEdit.html QTextEdit使用 QTextEdit常用函数 函数作用文本编辑类函数append在文本框的最后添加新内容clear清空文本框copy复制文本框内容cut剪切文本框内容paste粘贴文本框内容redo撤销文本框操作setText设置纯文本内容内容或html格式的字符串(该函数会覆盖原内容)setPlainText设置纯文本内容内容(该函数会覆盖原内容)toPlainText获取文本框内容文本框格式设置函数setTextColor设置字体颜色setTextBackgroundColor设置字体背景颜色setFont设置字体格式setStyleSheet设置文本框样式信号 textChanged文本框内容改变时触发 文本编辑类函数 self.ui.pushButton_2.clicked.connect(self.textedit_copy) self.ui.pushButton_4.clicked.connect(self.textedit_paste) self.ui.pushButton_5.clicked.connect(self.textedit_cut) self.ui.pushButton_3.clicked.connect(self.textedit_undo) self.ui.pushButton.clicked.connect(self.textedit_clear)self.ui.textEdit.setText(font colorblue size50Hello World/font) # 往文本框写入内容 self.ui.textEdit.append(ABCDEFGHJIK) # 往文本框后新增内容def textedit_selectionChanged(self):print(self.ui.textEdit_3.toPlainText())def textedit_textChanged(self):print(self.ui.textEdit_3.toPlainText())def textedit_copy(self):self.ui.textEdit.copy() # 复制文本框内容def textedit_paste(self):self.ui.textEdit.paste() # 粘贴内容def textedit_cut(self):self.ui.textEdit.cut() # 剪切内容def textedit_undo(self):self.ui.textEdit.undo() # 撤销操作def textedit_clear(self):self.ui.textEdit.clear() # 清除文本框内容文本框格式设置函数 设置文字颜色 调用setTextColor设置文字颜色其参数为RGB888的颜色格式 self.ui.textEdit_2.setTextColor(QColor(255,0,0)) # 设置文本框字体颜色为红色设置文字背景颜色 调用setTextBackgroundColor设置文字背景颜色其参数也是为RGB888的颜色格式 self.ui.textEdit_2.setTextBackgroundColor(QColor(0,0,255)) # 设置字体背景颜色为蓝色设置文字格式 QTextEdit支持文字的大小设置、下划线设置、加粗设置和倾斜设置。 font QFont() font.setPointSize(20) # 设置字体大小 font.setUnderline(True) # 添加字体下划线 font.setBold(True) # 设置字体为粗体 font.setItalic(True) # 设置字体为斜体 self.ui.textEdit_2.setFont(font) # 设置字体格式设置文本框样式 文本框样式设置可以通过代码设置和界面设置本人比较推荐通过界面设置因为程序设置比较复杂。 程序设置 设置文本框背景颜色为绿色 self.ui.textEdit_2.setStyleSheet(background-color:#00FF00) # 设置文本框背景颜色为绿色界面设置 找到TextEdit控件的属性栏找到styleSheet选项点击右边的小方块进入样式设置对话框。在颜色对话框就可以设置背景颜色字体格式等操作。在这里插入代码片 font QFont() font.setPointSize(20) # 设置字体大小 font.setUnderline(True) # 添加字体下划线 font.setBold(True) # 设置字体为粗体 font.setItalic(True) # 设置字体为斜体 self.ui.textEdit_2.setFont(font) # 设置字体格式self.ui.textEdit_2.setStyleSheet(background-color:#00FF00) # 设置文本框背景颜色为绿色self.ui.textEdit_2.setTextColor(QColor(255,0,0)) # 设置文本框字体颜色为红色 self.ui.textEdit_2.setTextBackgroundColor(QColor(0,0,255)) # 设置字体背景颜色为蓝色 self.ui.textEdit_2.append(0123456789) # 往文本框写入内容self.ui.textEdit_2.setTextColor(QColor(0,0,255)) # 设置文本框字体颜色为蓝色 self.ui.textEdit_2.setTextBackgroundColor(QColor(255,0,0)) # 设置字体背景颜色为红色 self.ui.textEdit_2.append(ABCDEFGHJIK) # 往文本框写入内容QTextEdit信号 textChanged信号 textChanged信号是文本框内容改变的时候触发注意如果在界面初始化时调用setText或者setPlainText设置文本时不会触发textChanged信号。 self.ui.textEdit_3.textChanged.connect(self.textedit_textChanged) # 绑定textChanged信号 def textedit_textChanged(self):print(self.ui.textEdit_3.toPlainText())完整程序 界面程序 ?xml version1.0 encodingUTF-8? ui version4.0classMainWindow/classwidget classQMainWindow nameMainWindowproperty namegeometryrectx0/xy0/ywidth778/widthheight577/height/rect/propertyproperty namefontfontpointsize11/pointsize/font/propertyproperty namewindowTitlestringMainWindow/string/propertywidget classQWidget namecentralwidgetlayout classQVBoxLayout nameverticalLayoutitemwidget classQTabWidget nametabWidgetproperty namefontfontpointsize11/pointsizeitalicfalse/italicboldfalse/bold/font/propertyproperty namecurrentIndexnumber0/number/propertywidget classQWidget nametabattribute nametitlestring文本编辑操作/string/attributelayout classQHBoxLayout namehorizontalLayoutitemwidget classQTextEdit nametextEditproperty namefontfontpointsize11/pointsizeitalicfalse/italicboldfalse/bold/font/propertyproperty namecursor stdset0cursorShapeArrowCursor/cursorShape/propertyproperty namehtmlstringlt;!DOCTYPE HTML PUBLIC quot;-//W3C//DTD HTML 4.0//ENquot; quot;http://www.w3.org/TR/REC-html40/strict.dtdquot;gt; lt;htmlgt;lt;headgt;lt;meta namequot;qrichtextquot; contentquot;1quot; /gt;lt;meta charsetquot;utf-8quot; /gt;lt;style typequot;text/cssquot;gt; p, li { white-space: pre-wrap; } hr { height: 1px; border-width: 0; } li.unchecked::marker { content: quot;\2610quot;; } li.checked::marker { content: quot;\2612quot;; } lt;/stylegt;lt;/headgt;lt;body stylequot; font-family:Microsoft YaHei UI; font-size:11pt; font-weight:400; font-style:normal;quot;gt; lt;p stylequot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;quot;gt;lt;br /gt;lt;/pgt;lt;/bodygt;lt;/htmlgt;/string/property/widget/itemitemlayout classQVBoxLayout nameverticalLayout_2itemwidget classQPushButton namepushButton_2property nametextstring复制/string/property/widget/itemitemwidget classQPushButton namepushButton_4property nametextstring粘贴/string/property/widget/itemitemwidget classQPushButton namepushButton_5property nametextstring剪切/string/property/widget/itemitemwidget classQPushButton namepushButton_3property nametextstring撤销/string/property/widget/itemitemwidget classQPushButton namepushButtonproperty nametextstring清除/string/property/widget/item/layout/item/layout/widgetwidget classQWidget nametab_2attribute nametitlestring文本框格式设置/string/attributelayout classQVBoxLayout nameverticalLayout_3itemwidget classQTextEdit nametextEdit_2property namefontfontpointsize11/pointsizeitalicfalse/italicboldfalse/bold/font/propertyproperty namestyleSheetstring notrtrue//propertyproperty namehtmlstringlt;!DOCTYPE HTML PUBLIC quot;-//W3C//DTD HTML 4.0//ENquot; quot;http://www.w3.org/TR/REC-html40/strict.dtdquot;gt; lt;htmlgt;lt;headgt;lt;meta namequot;qrichtextquot; contentquot;1quot; /gt;lt;meta charsetquot;utf-8quot; /gt;lt;style typequot;text/cssquot;gt; p, li { white-space: pre-wrap; } hr { height: 1px; border-width: 0; } li.unchecked::marker { content: quot;\2610quot;; } li.checked::marker { content: quot;\2612quot;; } lt;/stylegt;lt;/headgt;lt;body stylequot; font-family:Microsoft YaHei UI; font-size:11pt; font-weight:400; font-style:normal;quot;gt; lt;p stylequot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;quot;gt;lt;br /gt;lt;/pgt;lt;/bodygt;lt;/htmlgt;/string/property/widget/item/layout/widgetwidget classQWidget nametab_3attribute nametitlestring信号/string/attributelayout classQVBoxLayout nameverticalLayout_4itemwidget classQTextEdit nametextEdit_3//item/layout/widget/widget/item/layout/widgetwidget classQMenuBar namemenubarproperty namegeometryrectx0/xy0/ywidth778/widthheight26/height/rect/property/widgetwidget classQStatusBar namestatusbar//widgetresources/connections/ /ui 主程序 # Import Qt libraries from PySide6.QtWidgets import * from PySide6.QtCore import QFile,QByteArray from PySide6.QtGui import QFont,QColor,Qt,QTextCursor # Import UI developed in Qt Creator from qtextedit_ui import Ui_MainWindow # 导入界面 # Import PseudoSensor # Import system tools and datetime import sys import statistics import time from datetime import datetime# Create and start the Qt application class MainWindow(QMainWindow):def __init__(self):super(MainWindow, self).__init__()# 设置界面为用户设计的界面self.ui Ui_MainWindow() self.ui.setupUi(self) self.ui.pushButton_2.clicked.connect(self.textedit_copy)self.ui.pushButton_4.clicked.connect(self.textedit_paste)self.ui.pushButton_5.clicked.connect(self.textedit_cut)self.ui.pushButton_3.clicked.connect(self.textedit_undo)self.ui.pushButton.clicked.connect(self.textedit_clear)self.ui.textEdit.setText(font colorblue size50Hello World/font) # 往文本框写入内容self.ui.textEdit.append(ABCDEFGHJIK) # 往文本框后新增内容font QFont()font.setPointSize(20) # 设置字体大小font.setUnderline(True) # 添加字体下划线font.setBold(True) # 设置字体为粗体font.setItalic(True) # 设置字体为斜体self.ui.textEdit_2.setFont(font) # 设置字体格式self.ui.textEdit_2.setStyleSheet(background-color:#00FF00) # 设置文本框背景颜色为绿色self.ui.textEdit_2.setTextColor(QColor(255,0,0)) # 设置文本框字体颜色为红色self.ui.textEdit_2.setTextBackgroundColor(QColor(0,0,255)) # 设置字体背景颜色为蓝色self.ui.textEdit_2.append(0123456789) # 往文本框写入内容self.ui.textEdit_2.setTextColor(QColor(0,0,255)) # 设置文本框字体颜色为蓝色self.ui.textEdit_2.setTextBackgroundColor(QColor(255,0,0)) # 设置字体背景颜色为红色self.ui.textEdit_2.append(ABCDEFGHJIK) # 往文本框写入内容self.ui.textEdit_3.textChanged.connect(self.textedit_textChanged) # 绑定textChanged信号def textedit_textChanged(self):print(self.ui.textEdit_3.toPlainText())def textedit_copy(self):self.ui.textEdit.copy() # 复制文本框内容def textedit_paste(self):self.ui.textEdit.paste() # 粘贴内容def textedit_cut(self):self.ui.textEdit.cut() # 剪切内容def textedit_undo(self):self.ui.textEdit.undo() # 撤销操作def textedit_clear(self):self.ui.textEdit.clear() # 清除文本框内容def closeAndExit(self):sys.exit()if __name__ __main__:app QApplication(sys.argv) # 初始化QApplication# 初始化界面并显示界面window MainWindow() window.show() window.setFixedSize(window.width(), window.height())sys.exit(app.exec())
http://www.dnsts.com.cn/news/98869.html

相关文章:

  • 学院网站建设管理山东省建设教育集团网站
  • 全国二级建造师查询网站外包加工网是不是骗钱的
  • wordpress更改主站点网站建设与管理考题
  • 云南制作网站的公司建设网站的公司兴田德润怎么联系
  • 阿里云网站建设步骤app软件开发软件
  • 宁夏建设厅网站公示wifi域名是什么
  • 设计师自己的网站网站域名迁移公告
  • 网站导航html源码服务专业的网站开发设计
  • 商务网站开发设计安徽省建筑人员信息网
  • 网站建设总结与心得体会怎样用dw做 网站首页
  • 建网站怎么建手机网站建设的图片
  • 江门建站网站模板网站站点
  • 手机投资网站网站服务器在
  • 深圳网站建设新闻拍摄广告片制作公司
  • 做网站我网站找第三方支付如何修改wordpress的域名
  • wordpress站点更换域名广告设计找工作
  • 合肥外贸网站建设公司价格有域名了怎么建站
  • 单页面网站教程网站和discuz同步登录
  • 什么是网站黏着度商标注册45大类明细
  • 拖拽建站系统源码建外贸企业网站
  • 建设外贸型网站流程平顶山工程造价信息网
  • 做天猫还是做网站推广详情页面设计
  • 哪个网站做漫画可以有钱北京朝林建设集团网站
  • wordpress建站要钱么网上怎样找装修设计师
  • 矿泉水网站模板互联网营销师证书
  • 登陆工伤保险网站 提示未授权 怎么做网站制作的管理
  • 什么网站做视频赚钱南宁推广平台
  • 2万块建一个网站贵吗完整网页开发
  • 专门做教育咨询有限公司网站重庆网站制作建设
  • 公司网站要备案吗上海专建贸易有限公司