本文整理汇总了Python中PyQt5.QtGui.QTextCharFormat.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat.setBackground方法的具体用法?Python QTextCharFormat.setBackground怎么用?Python QTextCharFormat.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextCharFormat
的用法示例。
在下文中一共展示了QTextCharFormat.setBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: css2fmt
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def css2fmt(d, f=None):
"""Convert a css dictionary to a QTextCharFormat."""
if f is None:
f = QTextCharFormat()
v = d.get('font-style')
if v:
f.setFontItalic(v in ('oblique', 'italic'))
v = d.get('font-weight')
if v:
if v == 'bold':
f.setFontWeight(QFont.Bold)
elif v == 'normal':
f.setFontWeight(QFont.Normal)
elif v.isdigit():
f.setFontWeight(int(v) / 10)
v = d.get('color')
if v:
f.setForeground(QColor(v))
v = d.get('background')
if v:
f.setBackground(QColor(v))
v = d.get('text-decoration')
if v:
f.setFontUnderline(v == 'underline')
v = d.get('text-decoration-color')
if v:
f.setUnderlineColor(QColor(v))
return f
示例2: highlightBlock
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def highlightBlock(self, text):
# Syntax highlighter
if self.docType in self.patternsDict:
for number in self.patternsDict[self.docType]:
pattern = self.patterns[number]
for match in pattern[0].finditer(text):
for i, formatter in enumerate(pattern[1:]):
charFormat = QTextCharFormat()
formatter.format(charFormat)
self.setFormat(QString_length(text[:match.start(i)]),
QString_length(match.group(i)),
charFormat)
for match in reSpacesOnEnd.finditer(text):
charFormat = QTextCharFormat()
charFormat.setBackground(colorScheme['whitespaceOnEnd'])
self.setFormat(QString_length(text[:match.start()]),
QString_length(match.group(0)),
charFormat)
# Spell checker
if self.dictionary:
charFormat = QTextCharFormat()
charFormat.setUnderlineColor(Qt.red)
charFormat.setUnderlineStyle(QTextCharFormat.WaveUnderline)
for match in reWords.finditer(text):
finalFormat = QTextCharFormat()
finalFormat.merge(charFormat)
finalFormat.merge(self.format(match.start()))
if not self.dictionary.check(match.group(0)):
self.setFormat(QString_length(text[:match.start()]),
QString_length(match.group(0)),
finalFormat)
示例3: highlightItem
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
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)
示例4: highlightBlock
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def highlightBlock(self, text):
patterns = (
# regex, color, font style, italic, underline
(reHtmlTags, 'htmlTags', QFont.Bold), # 0
(reHtmlSymbols, 'htmlSymbols', QFont.Bold), # 1
(reHtmlStrings, 'htmlStrings', QFont.Bold), # 2
(reHtmlComments, 'htmlComments', QFont.Normal), # 3
(reAsterisks, None, QFont.Normal, True), # 4
(reUnderline, None, QFont.Normal, True), # 5
(reDblAsterisks, None, QFont.Bold), # 6
(reDblUnderline, None, QFont.Bold), # 7
(reTrpAsterisks, None, QFont.Bold, True), # 8
(reTrpUnderline, None, QFont.Bold, True), # 9
(reMkdHeaders, None, QFont.Black), # 10
(reMkdLinksImgs, 'markdownLinks', QFont.Normal), # 11
(reMkdLinkRefs, None, QFont.Normal, True, True), # 12
(reBlockQuotes, 'blockquotes', QFont.Normal), # 13
(reReSTDirects, 'restDirectives', QFont.Bold), # 14
(reReSTRoles, 'restRoles', QFont.Bold), # 15
(reTextileHdrs, None, QFont.Black), # 16
(reTextileQuot, 'blockquotes', QFont.Normal), # 17
(reAsterisks, None, QFont.Bold), # 18
(reDblUnderline, None, QFont.Normal, True), # 19
)
patternsDict = {
'Markdown': (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
'reStructuredText': (4, 6, 14, 15),
'Textile': (0, 5, 6, 16, 17, 18, 19),
'html': (0, 1, 2, 3)
}
# Syntax highlighter
if self.docType in patternsDict:
for number in patternsDict[self.docType]:
pattern = patterns[number]
charFormat = QTextCharFormat()
charFormat.setFontWeight(pattern[2])
if pattern[1] != None:
charFormat.setForeground(colorScheme[pattern[1]])
if len(pattern) >= 4:
charFormat.setFontItalic(pattern[3])
if len(pattern) >= 5:
charFormat.setFontUnderline(pattern[4])
for match in pattern[0].finditer(text):
self.setFormat(match.start(), match.end() - match.start(), charFormat)
for match in reSpacesOnEnd.finditer(text):
charFormat = QTextCharFormat()
charFormat.setBackground(colorScheme['whitespaceOnEnd'])
self.setFormat(match.start(), match.end() - match.start(), charFormat)
# Spell checker
if self.dictionary:
charFormat = QTextCharFormat()
charFormat.setUnderlineColor(Qt.red)
charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
for match in reWords.finditer(text):
finalFormat = QTextCharFormat()
finalFormat.merge(charFormat)
finalFormat.merge(self.format(match.start()))
if not self.dictionary.check(match.group(0)):
self.setFormat(match.start(), match.end() - match.start(), finalFormat)
示例5: removeHighlighting
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
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)
示例6: highlight
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
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)
示例7: make_format
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
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
示例8: Matcher
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
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'])
示例9: fixFormat
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
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)
示例10: textFormat
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def textFormat(self, name):
"""(Internal) Returns a QTextCharFormat setup according to the preferences.
For bookmarks and the current line, FullWidthSelection is automatically enabled.
"""
f = QTextCharFormat()
f.setBackground(self._baseColors[name])
if name in ('current', 'mark', 'error'):
f.setProperty(QTextFormat.FullWidthSelection, True)
return f
示例11: eltToStyle
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def eltToStyle(elt):
fmt = QTextCharFormat()
if elt.get('bold'):
fmt.setFontWeight(QFont.Bold if toBool(elt.get('bold')) else QFont.Normal)
if elt.get('italic'):
fmt.setFontItalic(toBool(elt.get('italic')))
if elt.get('underline'):
fmt.setFontUnderline(toBool(elt.get('underline')))
if elt.get('textColor'):
fmt.setForeground(QColor(elt.get('textColor')))
if elt.get('backgroundColor'):
fmt.setBackground(QColor(elt.get('backgroundColor')))
if elt.get('underlineColor'):
fmt.setUnderlineColor(QColor(elt.get('underlineColor')))
return fmt
示例12: html_copy
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def html_copy(cursor, scheme='editor', number_lines=False):
"""Return a new QTextDocument with highlighting set as HTML textcharformats.
The cursor is a cursor of a document.Document instance. If the cursor
has a selection, only the selection is put in the new document.
If number_lines is True, line numbers are added.
"""
data = textformats.formatData(scheme)
doc = QTextDocument()
doc.setDefaultFont(data.font)
doc.setPlainText(cursor.document().toPlainText())
if metainfo.info(cursor.document()).highlighting:
highlight(doc, mapping(data), ly.lex.state(documentinfo.mode(cursor.document())))
if cursor.hasSelection():
# cut out not selected text
start, end = cursor.selectionStart(), cursor.selectionEnd()
cur1 = QTextCursor(doc)
cur1.setPosition(start, QTextCursor.KeepAnchor)
cur2 = QTextCursor(doc)
cur2.setPosition(end)
cur2.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
cur2.removeSelectedText()
cur1.removeSelectedText()
if number_lines:
c = QTextCursor(doc)
f = QTextCharFormat()
f.setBackground(QColor('#eeeeee'))
if cursor.hasSelection():
num = cursor.document().findBlock(cursor.selectionStart()).blockNumber() + 1
last = cursor.document().findBlock(cursor.selectionEnd())
else:
num = 1
last = cursor.document().lastBlock()
lastnum = last.blockNumber() + 1
padding = len(format(lastnum))
block = doc.firstBlock()
while block.isValid():
c.setPosition(block.position())
c.setCharFormat(f)
c.insertText('{0:>{1}d} '.format(num, padding))
block = block.next()
num += 1
return doc
示例13: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def __init__(self, *args, **kwargs):
Formatter.__init__(self)
self.data=[]
self.styles={}
for token, style in self.style:
qtf=QTextCharFormat()
if style['color']:
qtf.setForeground(self.hex2QColor(style['color']))
if style['bgcolor']:
qtf.setBackground(self.hex2QColor(style['bgcolor']))
if style['bold']:
qtf.setFontWeight(QFont.Bold)
if style['italic']:
qtf.setFontItalic(True)
if style['underline']:
qtf.setFontUnderline(True)
self.styles[str(token)]=qtf
return
示例14: formatConverterFunction
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def formatConverterFunction(format):
if format == qutepart.syntax.TextFormat():
return None # Do not apply default format. Performance optimization
qtFormat = QTextCharFormat()
foregroundColor = QColor(format.color)
backgroundColor = QColor(format.background)
if foregroundColor != Qt.black:
qtFormat.setForeground(foregroundColor)
if backgroundColor != Qt.white:
qtFormat.setBackground(backgroundColor)
qtFormat.setFontItalic(format.italic)
qtFormat.setFontWeight(QFont.Bold if format.bold else QFont.Normal)
qtFormat.setFontUnderline(format.underline)
qtFormat.setFontStrikeOut(format.strikeOut)
return qtFormat
示例15: add_io
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setBackground [as 别名]
def add_io(self, vbox):
if self.tx.locktime > 0:
vbox.addWidget(QLabel("LockTime: %d\n" % self.tx.locktime))
vbox.addWidget(QLabel(_("Inputs") + ' (%d)'%len(self.tx.inputs())))
ext = QTextCharFormat()
rec = QTextCharFormat()
rec.setBackground(QBrush(ColorScheme.GREEN.as_color(background=True)))
rec.setToolTip(_("Wallet receive address"))
chg = QTextCharFormat()
chg.setBackground(QBrush(ColorScheme.YELLOW.as_color(background=True)))
chg.setToolTip(_("Wallet change address"))
twofactor = QTextCharFormat()
twofactor.setBackground(QBrush(ColorScheme.BLUE.as_color(background=True)))
twofactor.setToolTip(_("TrustedCoin (2FA) fee for the next batch of transactions"))
def text_format(addr):
if self.wallet.is_mine(addr):
return chg if self.wallet.is_change(addr) else rec
elif self.wallet.is_billing_address(addr):
return twofactor
return ext
def format_amount(amt):
return self.main_window.format_amount(amt, whitespaces=True)
i_text = QTextEditWithDefaultSize()
i_text.setFont(QFont(MONOSPACE_FONT))
i_text.setReadOnly(True)
cursor = i_text.textCursor()
for x in self.tx.inputs():
if x['type'] == 'coinbase':
cursor.insertText('coinbase')
else:
prevout_hash = x.get('prevout_hash')
prevout_n = x.get('prevout_n')
cursor.insertText(prevout_hash + ":%-4d " % prevout_n, ext)
addr = self.wallet.get_txin_address(x)
if addr is None:
addr = ''
cursor.insertText(addr, text_format(addr))
if x.get('value'):
cursor.insertText(format_amount(x['value']), ext)
cursor.insertBlock()
vbox.addWidget(i_text)
vbox.addWidget(QLabel(_("Outputs") + ' (%d)'%len(self.tx.outputs())))
o_text = QTextEditWithDefaultSize()
o_text.setFont(QFont(MONOSPACE_FONT))
o_text.setReadOnly(True)
cursor = o_text.textCursor()
for o in self.tx.get_outputs_for_UI():
addr, v = o.address, o.value
cursor.insertText(addr, text_format(addr))
if v is not None:
cursor.insertText('\t', ext)
cursor.insertText(format_amount(v), ext)
cursor.insertBlock()
vbox.addWidget(o_text)