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彩色模式。

    以前-好记性不如烂笔头 现在-好记性不如烂键盘
  • 相关阅读:
    [C++] 变量
    [C++] 算术类型
    [C++] 回调函数(转)
    [国嵌攻略][095][脚本编程技术]
    [国嵌攻略][094][守护进程设计]
    [国嵌攻略][093][并发服务器设计]
    [国嵌攻略][092][UDP网络程序设计]
    [国嵌攻略][091][TCP网络程序设计]
    [国嵌攻略][090][linux网络编程模型]
    [国嵌攻略][089][网络协议分析]
  • 原文地址:https://www.cnblogs.com/gexbooks/p/14768421.html
Copyright © 2011-2022 走看看