本文整理汇总了Python中PySide.QtGui.QTextEdit.setTextColor方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.setTextColor方法的具体用法?Python QTextEdit.setTextColor怎么用?Python QTextEdit.setTextColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.setTextColor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ui_MainWindow
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import setTextColor [as 别名]
#.........这里部分代码省略.........
def update_comp_table(self):
"""Met à jour le tableau de comparaison ASCII VS Huffman."""
self.compTabASCIIMem.setText(unicode(len(''.join(self.aSqueezed))))
self.compTabHuffMem.setText(unicode(len(''.join(self.hSqueezed))))
# entropie ?
self.compTabASCIIEnt.setText('0')
self.compTabHuffEnt.setText('0')
self.compTabASCIIAvg.setText(unicode(8))
self.compTabHuffAvg.setText(unicode(
average_code_length(self.hSqueezed)))
self.compTable.resizeColumnsToContents()
def update_codes_table(self, hlRow=[]):
"""Met à jour le tableau des codes et surligne les lignes de hlRow."""
self.codesTableModel.hlRow = hlRow
self.codesTableModel.emptyTable()
self.codesTableModel.fillTable(self.make_tab_rows())
self.codesTable.resizeColumnsToContents()
def centerAndResize(self):
"""Centre et redimmensionne le widget."""
screen = QDesktopWidget().screenGeometry()
self.resize(screen.width() / 1.6, screen.height() / 1.4)
size = self.geometry()
self.move(
(screen.width() - size.width()) / 2,
(screen.height() - size.height()) / 2)
#===================== METHODS FOR EN/DECODE WIZARDS =====================#
def make_encode_init(self):
self.compressedText.setText(unicode(self.stringHSqueezed))
self.asciiText.setText(unicode(self.stringASqueezed))
self.orgText.setTextColor(QColor(Qt.darkGreen))
self.orgText.setText(unicode(self.text.decode('utf-8')))
self.update_codes_table()
def make_occ(self):
self.orgText.setTextColor(QColor(Qt.white))
self.orgText.setText(unicode(self.text.decode('utf-8')))
self.occ = occurences(self.text)
self.update_codes_table([0, 1])
def make_tree(self):
self.tree = make_trie(self.occ)
self.update_codes_table()
def make_codes(self):
self.hCodes = make_codes(self.tree, {})
self.aCodes = make_ascii_codes(self.occ.keys(), {})
self.update_codes_table([2, 3])
def make_cost(self):
self.hCost = tree_cost(self.hCodes, self.occ)
self.aCost = tree_cost(self.aCodes, self.occ)
self.update_codes_table([4, 5])
def make_encoded_text(self):
self.hSqueezed = squeeze(self.text, self.hCodes)
self.aSqueezed = squeeze(self.text, self.aCodes)
self.stringHSqueezed = ' '.join(self.hSqueezed)
self.stringASqueezed = ' '.join(self.aSqueezed)
self.compressedText.setTextColor(QColor(Qt.darkGreen))
self.asciiText.setTextColor(QColor(Qt.darkYellow))
self.compressedText.setText(unicode(self.stringHSqueezed))
self.asciiText.setText(unicode(self.stringASqueezed))
示例2: MainWindow
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import setTextColor [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())
#.........这里部分代码省略.........
示例3: CustomWidget
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import setTextColor [as 别名]
#.........这里部分代码省略.........
self.table.customContextMenuRequested.connect(self._tablePopup)
self.table.horizontalHeader().sectionDoubleClicked.connect(self._tableHeaderDoubleClicked)
self.table.cellDoubleClicked.connect(self._tableCellDoubleClicked)
def _createOutputTree(self):
"""
A QtreeWidget. Initially used to display those pesky
dword comparison to immediate values.
"""
self.tree_label = QtGui.QLabel('Tree Output')
self.tree = QTreeWidget()
self.tree.setColumnCount(3)
self.tree.setColumnWidth(0, 150)
self.tree.setColumnWidth(1, 150)
self.tree.setColumnWidth(2, 50)
# Connect signals to slots
self.tree.itemDoubleClicked.connect(self._treeElementDoubleClicked)
#################################################################
# GUI Callbacks
#################################################################
def _console_output(self, s = "", err = False):
"""
Convenience wrapper
"""
if err:
# Error message
err_color = QColor('red')
self.output_window.setTextColor(err_color)
self.output_window.append(s)
# restore original color
self.output_window.setTextColor(self.output_window.original_textcolor)
else:
self.output_window.append(s)
def _tableCellDoubleClicked(self, row, col):
"""
Most of the info displayed in QTableWidgets represent addresses.
Default action: try to jump to it.
"""
it = self.table.item(row, col).text()
try:
addr = int(it, 16)
jump_to_address(addr)
except ValueError:
self._console_output("[!] That does not look like an address...", err = True)
return
def _tablePopup(self, pos):
"""
Popup menu activated clicking the secondary
button on the table
"""
menu = QtGui.QMenu()
# Add menu entries