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