zoukankan      html  css  js  c++  java
  • pyqt5 QTextBrowser文本浏览器 字体/大小;字体颜色;背景颜色设置

    直接代码

        # 视图-浏览器字体/大小设置
        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彩色模式。

    以前-好记性不如烂笔头 现在-好记性不如烂键盘
  • 相关阅读:
    Centos7.6部署rsyslog+loganalyzer+mysql日志管理服务器
    linux编程基础
    天融信防火墙NGFW4000,无法进入web管理和community属性查看
    H3C_IRF_BFD配置
    H3C_IRF_LACP配置
    H3C_IRF
    h3c_7506e引擎主备镜像同步
    cisco4507引擎模式切换
    usg6000
    vpdn1
  • 原文地址:https://www.cnblogs.com/gexbooks/p/14768421.html
Copyright © 2011-2022 走看看