本文整理汇总了Python中PyQt5.QtGui.QTextCharFormat类的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat类的具体用法?Python QTextCharFormat怎么用?Python QTextCharFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextCharFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: XmlSyntaxHighlighter
class XmlSyntaxHighlighter(QSyntaxHighlighter):
def __init__(self, parent=None):
super(XmlSyntaxHighlighter, self).__init__(parent)
self.highlightingRules = []
# Tag format.
format = QTextCharFormat()
format.setForeground(Qt.darkBlue)
format.setFontWeight(QFont.Bold)
pattern = QRegExp("(<[a-zA-Z:]+\\b|<\\?[a-zA-Z:]+\\b|\\?>|>|/>|</[a-zA-Z:]+>)")
self.highlightingRules.append((pattern, format))
# Attribute format.
format = QTextCharFormat()
format.setForeground(Qt.darkGreen)
pattern = QRegExp("[a-zA-Z:]+=")
self.highlightingRules.append((pattern, format))
# Attribute content format.
format = QTextCharFormat()
format.setForeground(Qt.red)
pattern = QRegExp("(\"[^\"]*\"|'[^']*')")
self.highlightingRules.append((pattern, format))
# Comment format.
self.commentFormat = QTextCharFormat()
self.commentFormat.setForeground(Qt.lightGray)
self.commentFormat.setFontItalic(True)
self.commentStartExpression = QRegExp("<!--")
self.commentEndExpression = QRegExp("-->")
def highlightBlock(self, text):
for pattern, format in self.highlightingRules:
expression = QRegExp(pattern)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, format)
index = expression.indexIn(text, index + length)
self.setCurrentBlockState(0)
startIndex = 0
if self.previousBlockState() != 1:
startIndex = self.commentStartExpression.indexIn(text)
while startIndex >= 0:
endIndex = self.commentEndExpression.indexIn(text, startIndex)
if endIndex == -1:
self.setCurrentBlockState(1)
commentLength = text.length() - startIndex
else:
commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength()
self.setFormat(startIndex, commentLength, self.commentFormat)
startIndex = self.commentStartExpression.indexIn(text,
startIndex + commentLength)
示例2: highlightItem
def highlightItem(self, id):
'''Inform the view that it must highlight an Item.
Argument(s):
id (str): ID of the node we want to highlight
'''
cursor = self.textCursor()
fmt = self.textCursor().charFormat()
# Set BackgroundColor of all text in white
cursor.movePosition(QTextCursor.Start, QTextCursor.MoveAnchor)
cursor.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
fmt.setBackground(QBrush(QColor(0, 0, 0, 0)))
cursor.mergeCharFormat(fmt)
# Highlight item
infoPos = self.findPosItem(id)
cursor.setPosition(infoPos[0], QTextCursor.MoveAnchor)
cursor.setPosition(infoPos[1], QTextCursor.KeepAnchor)
# If subgraph in statement
if re.match("\s*(subgraph)*\s*.*\{", cursor.selectedText()):
indItem = cursor.selectedText().find(id)
cursor.setPosition(infoPos[0] + indItem, QTextCursor.MoveAnchor)
cursor.setPosition(infoPos[1], QTextCursor.KeepAnchor)
format = QTextCharFormat()
format.setBackground(QBrush(QColor(190, 180, 0, 80)))
cursor.mergeCharFormat(format)
self.setCurrentCharFormat(fmt)
示例3: FormatChoice
class FormatChoice( ChoiceWidget ) :
# combobox value
def __init__( self, title, explainer ) :
super().__init__( title, explainer )
#Current color and line style are kept in this QTextCharFormat
self.text_format = QTextCharFormat()
# Set up the underline menu
self.ul_menu = QComboBox()
self.ul_menu.addItems( list( UNDERLINES.values() ) )
self.ul_menu.currentIndexChanged[int].connect(self.ul_change)
self.layout().addWidget( self.ul_menu, 0 )
# Set up the color swatch
self.swatch = Swatch( self )
self.layout().addWidget( self.swatch, 0 )
self.swatch.clicked.connect( self.color_change )
# Set up the text sample
self.sample = Sample()
self.layout().addWidget( self.sample )
self.reset() # set widgets to current value
# Combine the underline choice and swatch color into a QTextCharFormat.
def make_format( self, ul_index, qc ) :
qtcf = QTextCharFormat()
qtcf.setUnderlineStyle( ul_index )
if ul_index == QTextCharFormat.NoUnderline :
qtcf.setBackground(QBrush(qc))
else :
qtcf.setUnderlineColor(qc) # underline color gets a QColor
qtcf.clearBackground()
return qtcf
# Parse self.text_format and display it in the swatch and combobox.
def show_format( self ) :
un = self.text_format.underlineStyle()
if un == QTextCharFormat.NoUnderline :
qc = self.text_format.background().color()
else :
qc = self.text_format.underlineColor()
self.swatch.set_color( qc )
self.ul_menu.setCurrentIndex( un )
self.sample.change_format(self.text_format)
# Handle a change in selection of the underline popup
def ul_change( self, index ) :
self.text_format = self.make_format( index, self.swatch.qc )
self.show_format()
# Handle a click on the color swatch. Show the color dialog. After it
# ends, the Preferences dialog will be behind the main window. Why? Who
# knows! But raise it back up to visibility.
def color_change(self) :
qc = colors.choose_color(
_TR('Browse dialog for color preference',
'Choose a color for scanno marking'),
self.swatch.qc )
BIG_FAT_KLUDGE.raise_()
if qc is not None :
self.text_format = self.make_format( self.ul_menu.currentIndex(), qc )
self.show_format()
示例4: __post_execution_message
def __post_execution_message(self):
"""Print post execution message."""
self.output.textCursor().insertText('\n\n')
format_ = QTextCharFormat()
format_.setAnchor(True)
format_.setForeground(Qt.green)
self.output.textCursor().insertText(
_translate("RunWidget", "Post Execution Script Successfully executed."), format_)
示例5: _get_underline
def _get_underline(self):
_format = QTextCharFormat()
if self.textCursor().charFormat().font().underline():
_format.setFontUnderline(False)
else:
_format.setFontUnderline(True)
return _format
示例6: _get_cursive
def _get_cursive(self):
_format = QTextCharFormat()
if self.textCursor().charFormat().font().italic():
_format.setFontItalic(False)
else:
_format.setFontItalic(True)
return _format
示例7: _get_bold
def _get_bold(self):
_format = QTextCharFormat()
if self.textCursor().charFormat().font().bold():
_format.setFontWeight(QFont.Normal)
else:
_format.setFontWeight(QFont.Bold)
return _format
示例8: removeHighlighting
def removeHighlighting(self):
""" Remove all the highlightings from the page content.
"""
cursor = self.pageContent.textCursor()
textFormat = QTextCharFormat()
cursor.select(QTextCursor.Document)
textFormat.setBackground(QBrush(QColor("transparent")))
cursor.mergeCharFormat(textFormat)
示例9: highlight
def highlight(begin, end, color, qtextedit):
form = QTextCharFormat()
form.setBackground(Qt.red)
cursor = QTextCursor(qtextedit.document())
cursor.setPosition(begin, QTextCursor.MoveAnchor)
cursor.setPosition(end, QTextCursor.KeepAnchor)
cursor.setCharFormat(form)
示例10: weekendFormatChanged
def weekendFormatChanged(self):
format = QTextCharFormat()
format.setForeground(
Qt.GlobalColor(
self.weekendColorCombo.itemData(
self.weekendColorCombo.currentIndex())))
self.calendar.setWeekdayTextFormat(Qt.Saturday, format)
self.calendar.setWeekdayTextFormat(Qt.Sunday, format)
示例11: addTestResult
def addTestResult(self, results):
textCharFormat = QTextCharFormat()
if results[0]:
textCharFormat.setFontWeight(QFont.Bold)
elif results[1] == False:
textCharFormat.setForeground(Qt.yellow)
self.plainTextEdit_methodResults.textCursor().insertText(results[2] + "\n", textCharFormat)
self.plainTextEdit_methodResults.verticalScrollBar().setValue(
self.plainTextEdit_methodResults.verticalScrollBar().maximum())
示例12: Matcher
class Matcher(gadgets.matcher.Matcher):
def __init__(self, edit):
super(Matcher, self).__init__(edit)
self.readSettings()
app.settingsChanged.connect(self.readSettings)
def readSettings(self):
self.format = QTextCharFormat()
self.format.setBackground(textformats.formatData('editor').baseColors['match'])
示例13: textColor
def textColor(self):
col = QColorDialog.getColor(self.textEdit.textColor(), self)
if not col.isValid():
return
fmt = QTextCharFormat()
fmt.setForeground(col)
self.mergeFormatOnWordOrSelection(fmt)
self.colorChanged(col)
示例14: fixFormat
def fixFormat(self):
try:
cursor_clear = self.__textEditor.textCursor()
format_clear = QTextCharFormat()
format_clear.setBackground(QBrush(QColor(30, 30, 30)))
cursor_clear.setPosition(0)
cursor_clear.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
cursor_clear.mergeCharFormat(format_clear)
except Exception as e:
print("something didn't work with fixFormat: ", e)
示例15: __init__
def __init__(self):
super(PugdebugFormatter, self).__init__()
for token, style in self.style:
format = QTextCharFormat()
if style["color"]:
color = QColor("#" + style["color"])
format.setForeground(color)
self.styles[str(token)] = format