本文整理匯總了Python中PyQt4.Qt.QTextCharFormat.setBackground方法的典型用法代碼示例。如果您正苦於以下問題:Python QTextCharFormat.setBackground方法的具體用法?Python QTextCharFormat.setBackground怎麽用?Python QTextCharFormat.setBackground使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt4.Qt.QTextCharFormat
的用法示例。
在下文中一共展示了QTextCharFormat.setBackground方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: highlight_to_char_format
# 需要導入模塊: from PyQt4.Qt import QTextCharFormat [as 別名]
# 或者: from PyQt4.Qt.QTextCharFormat import setBackground [as 別名]
def highlight_to_char_format(h):
ans = QTextCharFormat()
if h.bold:
ans.setFontWeight(QFont.Bold)
if h.italic:
ans.setFontItalic(True)
if h.fg is not None:
ans.setForeground(h.fg)
if h.bg is not None:
ans.setBackground(h.bg)
if h.underline is not None:
ans.setUnderlineStyle(underline_styles[h.underline])
if h.underline_color is not None:
ans.setUnderlineColor(h.underline_color.color())
return ans
示例2: __init__
# 需要導入模塊: from PyQt4.Qt import QTextCharFormat [as 別名]
# 或者: from PyQt4.Qt.QTextCharFormat import setBackground [as 別名]
def __init__(self, right=False, parent=None, show_open_in_editor=False):
PlainTextEdit.__init__(self, parent)
self.setFrameStyle(0)
self.show_open_in_editor = show_open_in_editor
self.side_margin = 0
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)
self.setFocusPolicy(Qt.NoFocus)
self.right = right
self.setReadOnly(True)
w = self.fontMetrics()
self.number_width = max(map(lambda x:w.width(str(x)), xrange(10)))
self.space_width = w.width(' ')
self.setLineWrapMode(self.WidgetWidth)
self.setTabStopWidth(tprefs['editor_tab_stop_width'] * self.space_width)
font = self.font()
ff = tprefs['editor_font_family']
if ff is None:
ff = default_font_family()
font.setFamily(ff)
font.setPointSize(tprefs['editor_font_size'])
self.setFont(font)
font = self.heading_font = QFont(self.font())
font.setPointSize(int(tprefs['editor_font_size'] * 1.5))
font.setBold(True)
theme = get_theme()
pal = self.palette()
pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg'))
pal.setColor(pal.AlternateBase, theme_color(theme, 'CursorLine', 'bg'))
pal.setColor(pal.Text, theme_color(theme, 'Normal', 'fg'))
pal.setColor(pal.Highlight, theme_color(theme, 'Visual', 'bg'))
pal.setColor(pal.HighlightedText, theme_color(theme, 'Visual', 'fg'))
self.setPalette(pal)
self.viewport().setCursor(Qt.ArrowCursor)
self.line_number_area = LineNumbers(self)
self.blockCountChanged[int].connect(self.update_line_number_area_width)
self.updateRequest.connect(self.update_line_number_area)
self.line_number_palette = pal = QPalette()
pal.setColor(pal.Base, theme_color(theme, 'LineNr', 'bg'))
pal.setColor(pal.Text, theme_color(theme, 'LineNr', 'fg'))
pal.setColor(pal.BrightText, theme_color(theme, 'LineNrC', 'fg'))
self.line_number_map = LineNumberMap()
self.search_header_pos = 0
self.changes, self.headers, self.images = [], [], OrderedDict()
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff), self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.diff_backgrounds = {
'replace' : theme_color(theme, 'DiffReplace', 'bg'),
'insert' : theme_color(theme, 'DiffInsert', 'bg'),
'delete' : theme_color(theme, 'DiffDelete', 'bg'),
'replacereplace': theme_color(theme, 'DiffReplaceReplace', 'bg'),
'boundary': QBrush(theme_color(theme, 'Normal', 'fg'), Qt.Dense7Pattern),
}
self.diff_foregrounds = {
'replace' : theme_color(theme, 'DiffReplace', 'fg'),
'insert' : theme_color(theme, 'DiffInsert', 'fg'),
'delete' : theme_color(theme, 'DiffDelete', 'fg'),
'boundary': QColor(0, 0, 0, 0),
}
for x in ('replacereplace', 'insert', 'delete'):
f = QTextCharFormat()
f.setBackground(self.diff_backgrounds[x])
setattr(self, '%s_format' % x, f)