pyqt5 QTextBrowser文本浏览器 字体/大小;字体颜色;背景颜色设置 您所在的位置:网站首页 pyqt5字体大小 pyqt5 QTextBrowser文本浏览器 字体/大小;字体颜色;背景颜色设置

pyqt5 QTextBrowser文本浏览器 字体/大小;字体颜色;背景颜色设置

2023-03-01 22:32| 来源: 网络整理| 查看: 265

直接代码

# 视图-浏览器字体/大小设置 def browser_word_style(self): (font, ok) = QFontDialog.getFont(self.textBrowser.font(), self, "浏览器字体/大小设置") if font: self.textBrowser.setFont(font) # 视图-浏览器字体颜色设置 def browser_word_color(self): col = QColorDialog.getColor(self.textBrowser.textColor(), self, "浏览器字体颜色设置") if col.isValid(): self.textBrowser.setTextColor(col) # 视图-浏览器背景颜色设置 def browser_background_color(self): col = QColorDialog.getColor(self.textBrowser.textColor(), self, "浏览器背景颜色设置") if col.isValid(): self.textBrowser.setStyleSheet( "background-color: rgb({}, {}, {});".format(col.red(), col.green(), col.blue()))

代码分析:

(font, ok) = QFontDialog.getFont(self.textBrowser.font(), self, "浏览器字体/大小设置") getFont(initial[,parent=None[,title=""[,options=QFontDialog.FontDialogOptions()]]])

参数类型:

initial - PySide2.QtGui.QFont

parent - PySide2.QtWidgets.QWidget

title - str

options - FontDialogOptions

 

返回类型:

PyTuple

col = QColorDialog.getColor(self.textBrowser.textColor(), self, "浏览器背景颜色设置") getColor([initial=Qt.white[,parent=None[,title=""[,options=QColorDialog.ColorDialogOptions()]]]])

参数类型:

initial - PySide2.QtGui.QColor

parent - PySide2.QtWidgets.QWidget

title - str

options - ColorDialogOptions

 

返回类型:

PySide2.QtGui.QColor

 

self.textBrowser.setStyleSheet( "background-color: rgb({}, {}, {});".format(col.red(), col.green(), col.blue()))

QColor类提供了获得不同颜色分量参数的方法,我们根据格式获得不同的参数就可以了。rgb为RGB彩色模式。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有