本文整理汇总了Python中PyQt5.QtGui.QTextCharFormat方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QTextCharFormat方法的具体用法?Python QtGui.QTextCharFormat怎么用?Python QtGui.QTextCharFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui
的用法示例。
在下文中一共展示了QtGui.QTextCharFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_format_from_style
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def _get_format_from_style(self, token, style):
""" Returns a QTextCharFormat for token by reading a Pygments style.
"""
result = QtGui.QTextCharFormat()
for key, value in list(style.style_for_token(token).items()):
if value:
if key == 'color':
result.setForeground(self._get_brush(value))
elif key == 'bgcolor':
result.setBackground(self._get_brush(value))
elif key == 'bold':
result.setFontWeight(QtGui.QFont.Bold)
elif key == 'italic':
result.setFontItalic(True)
elif key == 'underline':
result.setUnderlineStyle(
QtGui.QTextCharFormat.SingleUnderline)
elif key == 'sans':
result.setFontStyleHint(QtGui.QFont.SansSerif)
elif key == 'roman':
result.setFontStyleHint(QtGui.QFont.Times)
elif key == 'mono':
result.setFontStyleHint(QtGui.QFont.TypeWriter)
return result
示例2: format
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def format(color, style=''):
"""Return a QTextCharFormat with the given attributes.
"""
_color = QColor()
_color.setNamedColor(color)
_format = QTextCharFormat()
_format.setForeground(_color)
if 'bold' in style:
_format.setFontWeight(QFont.Bold)
if 'italic' in style:
_format.setFontItalic(True)
return _format
# Syntax styles that can be shared by all languages
示例3: _get_format_from_style
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def _get_format_from_style(self, token, style):
""" Returns a QTextCharFormat for token by reading a Pygments style.
"""
result = QtGui.QTextCharFormat()
for key, value in style.style_for_token(token).items():
if value:
if key == 'color':
result.setForeground(self._get_brush(value))
elif key == 'bgcolor':
result.setBackground(self._get_brush(value))
elif key == 'bold':
result.setFontWeight(QtGui.QFont.Bold)
elif key == 'italic':
result.setFontItalic(True)
elif key == 'underline':
result.setUnderlineStyle(
QtGui.QTextCharFormat.SingleUnderline)
elif key == 'sans':
result.setFontStyleHint(QtGui.QFont.SansSerif)
elif key == 'roman':
result.setFontStyleHint(QtGui.QFont.Times)
elif key == 'mono':
result.setFontStyleHint(QtGui.QFont.TypeWriter)
return result
示例4: set_bytes
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def set_bytes(self, bs):
with DisableUpdates(self.textedit):
self.pretty_mode = False
self.data = bs
chunks = HextEditor._split_by_printables(bs)
self.clear()
cursor = QTextCursor(self.textedit.document())
cursor.beginEditBlock()
try:
cursor.select(QTextCursor.Document)
cursor.setCharFormat(QTextCharFormat())
cursor.clearSelection()
for chunk in chunks:
if chr(chunk[0]) in qtprintable:
cursor.insertText(chunk.decode())
else:
for b in chunk:
self._insert_byte(cursor, b)
finally:
cursor.endEditBlock()
self.repaint() # needed to fix issue with py2app
示例5: highlight
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def highlight(self):
""" Apply text highlighting to current file.
Highlight text of selected case with red underlining.
#format_.setForeground(QtGui.QColor("#990000")) """
if self.selected_file is None:
return
if self.selected_file['fulltext'] is None:
return
format_ = QtGui.QTextCharFormat()
cursor = self.ui.textBrowser.textCursor()
for item in self.case_text:
try:
cursor.setPosition(int(item['pos0']), QtGui.QTextCursor.MoveAnchor)
cursor.setPosition(int(item['pos1']), QtGui.QTextCursor.KeepAnchor)
format_.setFontUnderline(True)
format_.setUnderlineColor(QtCore.Qt.red)
cursor.setCharFormat(format_)
except:
msg = "highlight, text length " + str(len(self.ui.textBrowser.toPlainText()))
msg += "\npos0:" + str(item['pos0']) + ", pos1:" + str(item['pos1'])
logger.debug(msg)
示例6: highlight
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def highlight(self, fid, textEdit):
""" Add coding and annotation highlights. """
cur = self.app.conn.cursor()
sql = "select pos0,pos1 from annotation where fid=? union all select pos0,pos1 from code_text where fid=?"
cur.execute(sql, [fid, fid])
annoted_coded = cur.fetchall()
format_ = QtGui.QTextCharFormat()
format_.setFontFamily(self.app.settings['font'])
format_.setFontPointSize(self.app.settings['fontsize'])
# remove formatting
cursor = textEdit.textCursor()
cursor.setPosition(0, QtGui.QTextCursor.MoveAnchor)
cursor.setPosition(len(textEdit.toPlainText()), QtGui.QTextCursor.KeepAnchor)
cursor.setCharFormat(format_)
# add formatting
for item in annoted_coded:
cursor.setPosition(int(item[0]), QtGui.QTextCursor.MoveAnchor)
cursor.setPosition(int(item[1]), QtGui.QTextCursor.KeepAnchor)
format_.setFontUnderline(True)
format_.setUnderlineColor(QtCore.Qt.red)
cursor.setCharFormat(format_)
示例7: _get_format
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def _get_format(self, token):
""" Returns a QTextCharFormat for token or None.
"""
if token in self._formats:
return self._formats[token]
result = self._get_format_from_style(token, self._style)
self._formats[token] = result
return result
示例8: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def __init__(self, parent=None):
super(Highlighter, self).__init__(parent)
keywordFormat = QtGui.QTextCharFormat()
keywordFormat.setForeground(QtCore.Qt.blue)
keywordFormat.setFontWeight(QtGui.QFont.Bold)
keywordPatterns = ["\\b{}\\b".format(k) for k in keyword.kwlist]
self.highlightingRules = [(QtCore.QRegExp(pattern), keywordFormat)
for pattern in keywordPatterns]
classFormat = QtGui.QTextCharFormat()
classFormat.setFontWeight(QtGui.QFont.Bold)
self.highlightingRules.append((QtCore.QRegExp("\\bQ[A-Za-z]+\\b"),
classFormat))
singleLineCommentFormat = QtGui.QTextCharFormat()
singleLineCommentFormat.setForeground(QtCore.Qt.gray)
self.highlightingRules.append((QtCore.QRegExp("#[^\n]*"),
singleLineCommentFormat))
quotationFormat = QtGui.QTextCharFormat()
quotationFormat.setForeground(QtCore.Qt.darkGreen)
self.highlightingRules.append((QtCore.QRegExp("\".*\""),
quotationFormat))
self.highlightingRules.append((QtCore.QRegExp("'.*'"),
quotationFormat))
示例9: update_preview
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def update_preview(self):
cursor = self.parent.previewView.textCursor()
cursor.setPosition(0)
cursor.movePosition(QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor)
# TODO
# Other kinds of text markup
previewCharFormat = QtGui.QTextCharFormat()
if self.foregroundCheck.isChecked():
previewCharFormat.setForeground(self.foregroundColor)
highlight = QtCore.Qt.transparent
if self.highlightCheck.isChecked():
highlight = self.highlightColor
previewCharFormat.setBackground(highlight)
font_weight = QtGui.QFont.Normal
if self.boldCheck.isChecked():
font_weight = QtGui.QFont.Bold
previewCharFormat.setFontWeight(font_weight)
if self.italicCheck.isChecked():
previewCharFormat.setFontItalic(True)
if self.underlineCheck.isChecked():
previewCharFormat.setFontUnderline(True)
previewCharFormat.setUnderlineColor(self.underlineColor)
previewCharFormat.setUnderlineStyle(
self.underline_styles[self.underlineType.currentText()])
previewCharFormat.setFontStyleStrategy(
QtGui.QFont.PreferAntialias)
cursor.setCharFormat(previewCharFormat)
cursor.clearSelection()
self.parent.previewView.setTextCursor(cursor)
示例10: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def __init__(self):
self.annotation_type = None
self.annotation_components = None
self.underline_styles = {
'Solid': QtGui.QTextCharFormat.SingleUnderline,
'Dashes': QtGui.QTextCharFormat.DashUnderline,
'Dots': QtGui.QTextCharFormat.DotLine,
'Wavy': QtGui.QTextCharFormat.WaveUnderline}
示例11: clear_annotations
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def clear_annotations(self):
if not self.are_we_doing_images_only:
cursor = self.pw.textCursor()
cursor.setPosition(0)
cursor.movePosition(
QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor)
previewCharFormat = QtGui.QTextCharFormat()
previewCharFormat.setFontStyleStrategy(
QtGui.QFont.PreferAntialias)
cursor.setCharFormat(previewCharFormat)
cursor.clearSelection()
self.pw.setTextCursor(cursor)
示例12: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def __init__(self, text_color=Qt.white, font=QtGui.QFont.DemiBold):
super(_StandardTextFormat, self).__init__()
self.setFontWeight(font)
self.setForeground(text_color)
self.setFontPointSize(13)
self.setVerticalAlignment(QtGui.QTextCharFormat.AlignMiddle)
# TODO: see `QTextEdit.setAlignment` for setting the time to the right
示例13: format
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def format(color, style=''):
"""Return a QTextCharFormat with the given attributes.
"""
_color = QColor()
_color.setNamedColor(color)
_format = QTextCharFormat()
_format.setForeground(_color)
if 'bold' in style:
_format.setFontWeight(QFont.Bold)
if 'italic' in style:
_format.setFontItalic(True)
return _format
示例14: format
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def format(color, style=""):
"""Return a QTextCharFormat with the given attributes."""
_color = QColor()
_color.setNamedColor(color)
_format = QTextCharFormat()
_format.setForeground(_color)
if "bold" in style:
_format.setFontWeight(QFont.Bold)
if "italic" in style:
_format.setFontItalic(True)
return _format
# Syntax styles
示例15: font
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextCharFormat [as 别名]
def font(self, family):
format = QtGui.QTextCharFormat()
format.setFontFamily(family)
self.MergeFormat(format)