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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM