当前位置: 首页>>代码示例>>Python>>正文


Python QPainter.font方法代码示例

本文整理汇总了Python中PySide.QtGui.QPainter.font方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.font方法的具体用法?Python QPainter.font怎么用?Python QPainter.font使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtGui.QPainter的用法示例。


在下文中一共展示了QPainter.font方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import font [as 别名]
 def paintEvent(self, event):
     contents_y = self.edit.verticalScrollBar().value()
     page_bottom = contents_y + self.edit.viewport().height()
     font_metrics = self.fontMetrics()
     current_block = self.edit.document().findBlock(self.edit.textCursor().position())
     painter = QPainter(self)
     line_count = 0
     block = self.edit.document().begin()
     while block.isValid():
         line_count += 1
         position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
         if position.y() > page_bottom:
             break
         bold = False
         if block == current_block:
             bold = True
             font = painter.font()
             font.setBold(True)
             painter.setFont(font)
             self.current = line_count
         painter.drawText(
             self.width() - font_metrics.width(str(line_count)) - 10,
             round(position.y()) - contents_y + font_metrics.ascent(),
             str(line_count),
         )
         if bold:
             font = painter.font()
             font.setBold(False)
             painter.setFont(font)
         block = block.next()
     self.highest_line = line_count
     painter.end()
     QWidget.paintEvent(self, event)
开发者ID:u2r,项目名称:pinguino-ide,代码行数:35,代码来源:line_number.py

示例2: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import font [as 别名]
 def paintEvent(self, event):
     """ Paints the widgets:
      - paints the background
      - paint each visible blocks that intersects the widget bbox.
     """
     painter = QPainter(self)
     painter.fillRect(event.rect(), self.back_brush)
     painter.setPen(self.text_pen)
     painter.setFont(self.font)
     w = self.width() - 2
     # better name lookup speed
     painter_drawText = painter.drawText
     align_right = Qt.AlignRight
     normal_font = painter.font()
     normal_font.setBold(False)
     bold_font = QFont(normal_font)
     bold_font.setBold(True)
     active = self.editor.codeEdit.textCursor().blockNumber()
     for vb in self.editor.codeEdit.visible_blocks:
         row = vb.row
         if row == active + 1:
             painter.setFont(bold_font)
         else:
             painter.setFont(normal_font)
         painter_drawText(0, vb.top, w, vb.height, align_right,
                          str(row))
     return Panel.paintEvent(self, event)
开发者ID:hofoen,项目名称:pcef-core,代码行数:29,代码来源:lines.py

示例3: _numberbar_paint

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import font [as 别名]
        def _numberbar_paint(self, number_bar, event):
            '''Paint number bar.'''

            font_metrics = self.fontMetrics()
            current_line = self.edit.document().findBlock(
                self.edit.textCursor().position()
            ).blockNumber() + 1

            block = self.edit.firstVisibleBlock()
            line_count = block.blockNumber()
            painter = QPainter(number_bar)
            painter.fillRect(event.rect(), self.palette().base())

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                line_count += 1
                block_top = self.edit.blockBoundingGeometry(block).\
                    translated(self.edit.contentOffset()).top()

                # Check if the position of the block is out side of the visible
                # area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break

                # We want the line number for the selected line to be bold.
                if line_count == current_line:
                    font = painter.font()
                    font.setBold(True)
                    font.setUnderline(True)
                    painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    font.setUnderline(False)
                    painter.setFont(font)

                # Draw the line number right justified at the position of the
                # line.
                paint_rect = QRect(0, block_top, number_bar.width(),
                                   font_metrics.height())
                painter.drawText(paint_rect, Qt.AlignRight,
                                 "{} ".format(unicode(line_count)))

                block = block.next()

            painter.end()
            return
开发者ID:453483289,项目名称:hrdev,代码行数:49,代码来源:gui.py

示例4: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import font [as 别名]
    def paintEvent(self, event):
        text = []
        text.append(['{0}; {1}'.format(self.parent.chunkData['X'], self.parent.chunkData['Y']), Qt.black])
        if self.parent.chunkData[14] > 0:
            text.append(['Gold = {0}'.format(self.parent.chunkData[14]), Qt.yellow])
        else:
            text.append(['', Qt.yellow])
        if self.parent.chunkData[15] > 0:
            text.append(['Iron = {0}'.format(self.parent.chunkData[15]), Qt.red])
        else:
            text.append(['', Qt.red])
        if self.parent.chunkData[56] > 0:
            text.append(['Diamond = {0}'.format(self.parent.chunkData[56]), Qt.cyan])
        else:
            text.append(['', Qt.cyan])
        if self.parent.chunkData[73] > 0:
            text.append(['Redstone = {0}'.format(self.parent.chunkData[73]), Qt.magenta])
        else:
            text.append(['', Qt.magenta])
        if self.parent.chunkData[49] > 0:
            text.append(['Obsidian = {0}'.format(self.parent.chunkData[49]), Qt.darkYellow])
        else:
            text.append(['', Qt.darkYellow])
        if self.parent.chunkData[21] > 0:
            text.append(['Lazurit = {0}'.format(self.parent.chunkData[21]), Qt.darkBlue])
        else:
            text.append(['', Qt.darkBlue])

        painter = QPainter()
        painter.begin(self)

        painter.drawRect(self.parent.leftMargin, self.parent.topMargin,
                         self.edgeLen, self.edgeLen)

        cX = self.parent.leftMargin + self.parent.vsepara
        cY = self.parent.topMargin + self.parent.hsepara

        alig = Qt.AlignCenter
        i = 0
        fontik = painter.font()
        for t in text:
            if i > 0:
                alig = Qt.AlignLeft
            painter.setPen(t[1])
            if i == 2:
                fontik.setUnderline(True)
            else:
                fontik.setUnderline(False)
            painter.setFont(fontik)
            painter.drawText(cX, cY, self.tBoxWidth, self.tBoxHeight, alig, t[0])
            cY += self.lineSpacing
            i += 1
            

        painter.end()
        del painter
开发者ID:ydanilin,项目名称:MinecraftMinerals,代码行数:58,代码来源:OverviewTest01.py

示例5: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import font [as 别名]
    def paintEvent(self, event):
        QPushButton.paintEvent(self, event)

        qp = QPainter()
        qp.begin(self)

        font = qp.font()
        font.setPixelSize(8)
        font.setWeight(QFont.Normal)
        qp.setFont(font)

        qp.drawText(event.rect().translated(1, 1), str(self._atomic_number))

        qp.end()
开发者ID:pymontecarlo,项目名称:pymontecarlo-gui,代码行数:16,代码来源:periodictable.py

示例6: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import font [as 别名]
    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)

        # Рисование цифр в ячейки таблицы
        for i in range(self.matrix_size):
            for j in range(self.matrix_size):
                # Если текущая ячейка относится к дефолтной судоку
                if self.def_num_matrix[i][j]:
                    painter.save()
                    # painter.setPen()
                    painter.setBrush(Qt.yellow)
                    x = i * self.cell_size
                    y = j * self.cell_size
                    w, h = self.cell_size, self.cell_size
                    painter.drawRect(x, y, w, h)
                    painter.restore()

        # TODO: Закомментировано
        # Если индекс ячейки под курсором валидный
        if 0 <= self.x_highlight_cell < self.matrix_size and 0 <= self.y_highlight_cell < self.matrix_size:
            # # Выделение всего столбца и строки пересекающих ячейку под курсором
            # painter.save()
            # painter.setBrush(Qt.lightGray)
            #
            # # Выделение строки
            # for i in range(self.matrix_size):
            #     painter.drawRect(i * self.cell_size,
            #                      self.y_highlight_cell * self.cell_size,
            #                      self.cell_size,
            #                      self.cell_size)
            #
            # # Выделение столбца
            # for j in range(self.matrix_size):
            #     painter.drawRect(self.x_highlight_cell * self.cell_size,
            #                      j * self.cell_size,
            #                      self.cell_size,
            #                      self.cell_size)
            #
            # painter.restore()

            x, y = self.x_highlight_cell, self.y_highlight_cell

            # Не подсвечиваем дефолтную ячейку
            if not self.def_num_matrix[x][y]:
                # Выделение ячейки под курсором
                painter.save()
                painter.setBrush(Qt.darkYellow)
                painter.drawRect(x * self.cell_size,
                                 y * self.cell_size,
                                 self.cell_size,
                                 self.cell_size)
                painter.restore()

        # Рисование цифр в ячейки таблицы
        for i in range(self.matrix_size):
            for j in range(self.matrix_size):
                num = self.matrix[i][j]
                if not num:
                    continue

                num = str(num)

                # Алгоритм изменения размера текста взят из http://stackoverflow.com/a/2204501
                # Для текущего пришлось немного адаптировать
                factor = (self.cell_size / 2) / painter.fontMetrics().width(num)
                if factor < 1 or factor > 1.25:
                    f = painter.font()
                    point_size = f.pointSizeF() * factor
                    if point_size > 0:
                        f.setPointSizeF(point_size)
                        painter.setFont(f)

                x = i * self.cell_size
                y = j * self.cell_size
                w, h = self.cell_size, self.cell_size
                painter.drawText(x, y, w, h, Qt.AlignCenter, num)

        # Рисование сетки таблицы
        y1, y2 = 0, 0

        factor = min(self.width(), self.height()) / self.default_size
        size = self.default_pen_size_1
        size2 = self.default_pen_size_2

        if factor < 1 or factor > 1.25:
            size *= factor
            if size < self.min_default_pen_size_2:
                size = self.min_default_pen_size_2

        painter.save()

        for i in range(self.matrix_size + 1):
            painter.setPen(QPen(Qt.black, size2 if i % 3 == 0 and i and i < self.matrix_size else size))
            painter.drawLine(0, y1, self.cell_size * self.matrix_size, y2)

            y1 += self.cell_size
            y2 += self.cell_size

#.........这里部分代码省略.........
开发者ID:gil9red,项目名称:sudoku,代码行数:103,代码来源:sudoku.py

示例7: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import font [as 别名]
    def paintEvent( self, event ):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(painter.Antialiasing)
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)

        x = self.rect().x()
        y = self.rect().y()
        w = self.rect().width() - 1
        h = self.rect().height() - 1
        r = 8

        # draw a rounded style
        if self._rolloutStyle == 2:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            # draw the triangle
            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)

        # draw a square style
        if self._rolloutStyle == 3:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRect(x + 1, y + 1, w - 1, h - 1)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRect(x, y, w - 1, h - 1)

        # draw a Maya style
        if self._rolloutStyle == 4:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            painter.setRenderHint(QPainter.Antialiasing, False)

            self.__drawTriangle(painter, x, y)

            # draw the borders - top
            headerHeight = 20

            headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
            headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)

            # Highlight
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)

            painter.drawRect(headerRect)
            painter.fillRect(headerRect, QColor(255, 255, 255, 18))

            # Shadow
            pen.setColor(self.palette().color(QPalette.Dark))
            painter.setPen(pen)
            painter.drawRect(headerRectShadow)

            if not self.isCollapsed():
                # draw the lover border
                pen = QPen(self.palette().color(QPalette.Dark))
                pen.setWidthF(0.8)
                painter.setPen(pen)

                offSet = headerHeight + 3
                bodyRect = QRect(x, y + offSet, w, h - offSet)
                bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
                painter.drawRect(bodyRect)

                pen.setColor(self.palette().color(QPalette.Light))
                pen.setWidthF(0.4)
                painter.setPen(pen)

                painter.drawRect(bodyRectShadow)

        # draw a boxed style
        elif self._rolloutStyle == 1:
#.........这里部分代码省略.........
开发者ID:Sugz,项目名称:Python,代码行数:103,代码来源:accd.py


注:本文中的PySide.QtGui.QPainter.font方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。