本文整理汇总了Python中PySide.QtGui.QTextEdit.setPalette方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.setPalette方法的具体用法?Python QTextEdit.setPalette怎么用?Python QTextEdit.setPalette使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.setPalette方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import setPalette [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
# QMainWindow.__init__(self)
super().__init__() # use super() to avoid explicit dependency on the base class name
# Note: must not pass the self reference to __init__ in this case!
self.resize(800, 600)
# Create the main content widget
mainWidget = QWidget(self)
self.setCentralWidget(mainWidget)
# Create a text component at the top area of the main widget
self.output = QTextEdit(mainWidget)
self.output.setReadOnly(True)
self.output.setLineWrapMode(QTextEdit.NoWrap);
# set the font
font = self.output.font()
font.setFamily("Courier")
font.setPointSize(10)
self.output.setFont(font)
# Set the background color
# self.output.setTextBackgroundColor(Qt.red) # Only sets the background color for the text itself, not for the whole widget
pal = self.output.palette()
pal.setColor(QPalette.Base, Qt.black)
self.output.setPalette(pal)
mainLayout = QVBoxLayout(mainWidget)
mainLayout.addWidget(self.output)
# Create buttons in a grid layout below the top area
buttonWidget = QWidget(mainWidget)
self.buttonLayout = QGridLayout(buttonWidget)
mainLayout.addWidget(buttonWidget)
# Add some buttons to execute python code
self.row = 0
self.column = 0
self.addButton("Clear console", lambda : self.output.clear())
self.newRow()
# Add buttons for all the examples - attention: do not make "examples"
# a local variable - otherwise, the Examples object would be destroyed
# at the end of __init__ !!!
self.examples = samplePackage.SampleModule.Examples(self)
for example in self.examples.getExamples():
if example is None:
self.newRow()
else:
self.addButton(example.label, example.function)
# In a Python program, sys.excepthook is called just before the program exits.
# So we can catch all fatal, uncaught exceptions and log them.
# NOTE: we must be sure not to set the excepthook BEFORE we an actually
# log something!!
sys.excepthook = self.logException
self.writelnColor(Qt.magenta,
"Python version: {0}.{1}.{2} ({3})".format(
sys.version_info[0],
sys.version_info[1],
sys.version_info[2],
sys.version_info[3]))
self.writelnColor(Qt.magenta,
"Qt version : {0}".format(qVersion()))
def logException(self, exctype, value, tb):
self.writelnColor(Qt.red,
("\nFATAL ERROR: Uncaught exception\n"
" {}: {}\n"
"{}\n".format(exctype.__name__, value, ''.join(traceback.format_tb(tb)))) )
def addButton(self, label, function):
theButton = QPushButton(label)
theButton.clicked.connect(function)
self.buttonLayout.addWidget(theButton, self.row, self.column)
self.column += 1
def newRow(self):
self.row += 1
self.column = 0
def writeColor(self, color, *text):
theText = ' '.join(map(str, text))
self.output.setTextColor(color)
# Note: append() adds a new paragraph!
#self.output.append(theText)
self.output.textCursor().movePosition(QTextCursor.End)
self.output.insertPlainText(theText)
# scroll console window to bottom
sb = self.output.verticalScrollBar()
sb.setValue(sb.maximum())
#.........这里部分代码省略.........
示例2: Ui_MainWindow
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import setPalette [as 别名]
#.........这里部分代码省略.........
self.compTable.verticalHeaderItem(i).setTextAlignment(
Qt.AlignRight)
self.compTable.setHorizontalHeaderItem(0, QTableWidgetItem("ASCII"))
self.compTable.setHorizontalHeaderItem(1, QTableWidgetItem("Huffman"))
# nom des items
self.compTabASCIIMem = QTableWidgetItem()
self.compTable.setItem(0, 0, self.compTabASCIIMem)
self.compTabASCIIEnt = QTableWidgetItem()
self.compTable.setItem(1, 0, self.compTabASCIIEnt)
self.compTabASCIIAvg = QTableWidgetItem()
self.compTable.setItem(2, 0, self.compTabASCIIAvg)
self.compTabHuffMem = QTableWidgetItem()
self.compTable.setItem(0, 1, self.compTabHuffMem)
self.compTabHuffEnt = QTableWidgetItem()
self.compTable.setItem(1, 1, self.compTabHuffEnt)
self.compTabHuffAvg = QTableWidgetItem()
self.compTable.setItem(2, 1, self.compTabHuffAvg)
# parem du tableau
self.compTable.horizontalHeader().setCascadingSectionResizes(False)
self.compTable.verticalHeader().setVisible(True)
font = QFont("Mono", 8)
self.compTable.setFont(font)
compGrid.addWidget(self.compTable, 1, 0, 1, 1)
self.analysGrid.addWidget(self.compGroup, 0, 0, 1, 1)
mainGrid.addWidget(analysGroup, 0, 1, 1, 1)
# -+++++++----------------- groupe du texte -----------------+++++++- #
groupBox = QGroupBox(u"Texte", centralwidget)
textGrid = QGridLayout(groupBox)
# -+++++++------------- groupe du texte original ------------+++++++- #
orgTextGroup = QGroupBox(u"Texte original (Ctrl+T)", groupBox)
orgTextGrid = QGridLayout(orgTextGroup)
self.orgText = QTextEdit(orgTextGroup)
self.orgText.setPalette(self.defaultPalette)
orgTextGrid.addWidget(self.orgText, 0, 0, 1, 1)
textGrid.addWidget(orgTextGroup, 0, 0, 1, 2)
# -+++++++------------ groupe du texte compressé ------------+++++++- #
compressedTextGroup = QGroupBox(u"Texte compressé (Ctrl+H)", groupBox)
compressedTextGrid = QGridLayout(compressedTextGroup)
self.compressedText = QTextEdit(compressedTextGroup)
self.compressedText.setPalette(self.defaultPalette)
compressedTextGrid.addWidget(self.compressedText, 0, 0, 1, 1)
textGrid.addWidget(compressedTextGroup, 1, 0, 1, 2)
# -+++++++------------ groupe pour le texte ascii -----------+++++++- #
asciiTextGroup = QGroupBox(u"Texte ASCII", groupBox)
asciiTextGrid = QGridLayout(asciiTextGroup)
self.asciiText = QTextBrowser(asciiTextGroup)
self.asciiText.setPalette(self.defaultPalette)
asciiTextGrid.addWidget(self.asciiText, 0, 0, 1, 1)
textGrid.addWidget(asciiTextGroup, 2, 0, 1, 2)
# -+++++++-------------------- label de log -----------------+++++++- #
self.logLab = QLabel(analysGroup)
textGrid.addWidget(self.logLab, 3, 0, 1, 2)
# -+++++++----------- bouton pour encoder le texte ----------+++++++- #
self.encodeBut = QPushButton(groupBox)
self.encodeBut.setStatusTip(
u"Cliquez sur ce bouton pour encoder le texte original.")
self.encodeBut.setText(u"ENCODER")
self.encodeBut.clicked.connect(self.encode_text)
textGrid.addWidget(self.encodeBut, 4, 0, 1, 1)
# -+++++++----------- bouton pour décoder le texte ----------+++++++- #
self.decodeBut = QPushButton(groupBox)
self.decodeBut.setStatusTip(
u"Cliquez sur ce bouton pour décoder le texte compressé.")
self.decodeBut.setText(u"DÉCODER")
self.decodeBut.clicked.connect(self.decode_text)