直接代碼
# 視圖-瀏覽器字體/大小設置 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彩色模式。