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


Python QPainter.save方法代码示例

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


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

示例1: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.save()
        self.rect = painter.viewport()
        self.rect.adjust(0, 0, -1, -1)
        painter.drawRect(QRectF(self.rect))
        
        self.prj.setupPrism(self.rect.height(), 68)
        self.prj.setupProjectionMatrix(self.alef, self.bet)
        
        # draw the prism
        self.drawCubick(painter, [0, 0, 0], 63, 16)
        
        mineCube = self.parent.presenter.mineCube
        for y in range(len(mineCube)):
            for z in range(len(mineCube[0])):
                for x in range(len(mineCube[0][0])):
                    if mineCube[y][z][x] in self.parent.selectedMinerals.list_:
                        colo = self.parent.selectedMinerals.\
                                                     getColor(mineCube[y][z][x])
                        self.drawCubick(painter, [x, y, z], color=colo)

        self.drawSliceCursor(painter, self.parent.presenter.elevation)

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

示例2: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]
 def paintEvent(self, pe):
   painter = QPainter(self)
   painter.save()
   gradient = QLinearGradient()
   gradient.setStart(self._grad_start)
   gradient.setFinalStop(self._grad_end)
   gradient.setColorAt(0, QColor(230, 230, 230))
   gradient.setColorAt(1, QColor(247, 247, 247))
   brush = QBrush(gradient)
   painter.setBrush(brush)
   pen = QPen(Qt.black)
   pen.setWidth(1)
   painter.setPen(pen)
   painter.drawPath(self._painter_path)
   painter.restore()
   font = QFont()
   font.setFamily("Tahoma")
   font.setPixelSize(11)
   font.setBold(True)
   pen = QPen(Qt.darkGray)
   painter.setPen(pen)
   painter.setFont(font)
   self_rect = QRect(self.rect())
   self_rect.moveTo(self._hor_margin, self._ver_margin // 2)
   painter.drawText(self_rect, Qt.AlignLeft, self._text)
开发者ID:github-account-because-they-want-it,项目名称:VisualScrape,代码行数:27,代码来源:ui_common.py

示例3: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]
 def paintEvent(self, pe):
   # make an arrow polygon right in the middle
   painter = QPainter(self)
   painter.setPen(Qt.NoPen)
   # draw the background transparent rect
   painter.save()
   painter.setOpacity(self.BACKGROUND_OPACITY)
   # get the rectangle coordinates it should extend over the whole width with only a portion at the center
   painter.setBrush(Qt.black)
   empty_space_percent = 1 - self.BACKROUND_HEIGHT_PERCENT
   rect_top = empty_space_percent / 2 * self.height()
   rect_height = self.BACKROUND_HEIGHT_PERCENT * self.height()
   painter.drawRect(0, rect_top, self.width(), rect_height)
   painter.restore()
   painter.setRenderHint(QPainter.Antialiasing)
   pen = QPen()
   pen.setWidth(self.ARROW_LINE_WIDTH)
   pen.setCapStyle(Qt.RoundCap)
   if self._mouse_inside:
     pen.setColor(self._hover_color)
   else:
     pen.setColor(self._normal_color)
   # get the arrow coords
   painter.setPen(pen)
   self_center = QPointF(self.width() / 2, self.height() / 2) # use this as the arrow tip for now
   if self._direction == self.LEFT:
     h_shift = self._arrow_width
   elif self._direction == self.RIGHT:
     h_shift = - self._arrow_width
   v_shift = self._arrow_height / 2
   top_point = self_center + QPointF(h_shift, - v_shift)
   bottom_point = self_center + QPointF(h_shift, v_shift)
   painter.drawLine(top_point, self_center)
   painter.drawLine(self_center, bottom_point)
开发者ID:github-account-because-they-want-it,项目名称:VisualScrape,代码行数:36,代码来源:support.py

示例4: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]
 def paintEvent(self, pe):
   if not self._hover_rect:
     super(TrackerWebView, self).paintEvent(pe)
   else:
     super(TrackerWebView, self).paintEvent(pe)
     hover_rect = self._hover_rect
     self._fixRectForScroll(hover_rect)
     painter = QPainter(self)
     painter.save()
     pen = QPen(Qt.red)
     pen.setWidth(2)
     painter.setPen(pen)
     painter.drawRect(hover_rect)
     painter.restore()
     # draw green rects around the similar elements
     pen = QPen()
     pen.setWidth(2)
     for field_info in self._fields_info:
       painter.save()
       web_elements = field_info.web_elements
       color = field_info.color
       pen.setColor(color)
       painter.setPen(pen)
       for elem in web_elements:
         elem_rect = elem.absoluteGeometry()
         painter.drawRoundedRect(self._fixRectForScroll(elem_rect), 2, 2)
       painter.restore()
开发者ID:github-account-because-they-want-it,项目名称:VisualScrape,代码行数:29,代码来源:browser.py

示例5: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]
    def paintEvent(self, event):
        cX = self.parent.leftMargin + self.scaleMarkLen
        cY = self.parent.topMargin + self.scaleMarkLen
        worldX = self.parent.chunkX*16
        worldZ = self.parent.chunkZ*16
        painter = QPainter()
        path = QPainterPath()
        painter.begin(self)
        painter.save()
        #painter.setFont(QFont('Arial Narrow', 8)) #QFont.Bold
        # draw scale
        x = cX
        y = cY
        painter.rotate(-90)
        for i in range(16):
            fr = QRectF(-y, x, self.scaleMarkLen, self.edgeLen)
            painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
            painter.drawRect(fr)
            #fr = QRectF(-y - 16*self.edgeLen - self.scaleMarkLen, x, self.scaleMarkLen, self.edgeLen)
            #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
            #painter.drawRect(fr)
            x += self.edgeLen
        painter.rotate(90)

        x = self.parent.leftMargin
        y = cY
        for i in range(16):
            fr = QRectF(x, y, self.scaleMarkLen, self.edgeLen)
            painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
            painter.drawRect(fr)
            #fr = QRectF(x + self.scaleMarkLen + 16*self.edgeLen, y, self.scaleMarkLen, self.edgeLen)
            #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
            #painter.drawRect(fr)
            y += self.edgeLen

        x = cX
        y = cY
        for i in range(16):
            for j in range(16):
                path.addRect(x, y, self.edgeLen, self.edgeLen)
                fr = QRectF(x, y, self.edgeLen, self.edgeLen)
                #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
                x += self.edgeLen
            x = cX
            y += self.edgeLen

        painter.drawPath(path)

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

示例6: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]
    def paintEvent(self, event):
        """Display a translucent rounded rectangle."""
        roundness = 10
        rect = self.rect()
        bgcolor = self.palette().color(QPalette.Background)
        alpha_bgcolor = QColor(50, 50, 50, 150)
        # alpha_bgcolor = QColor(bgcolor.red(), bgcolor.green(),
        #    bgcolor.blue(), 150)

        painter = QPainter()
        painter.begin(self)
        painter.save()
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.red)
        rounded_rect = QPainterPath()
        rounded_rect.addRoundRect(1, 1, rect.width() - 2, rect.height() - 2, roundness, roundness)
        painter.setClipPath(rounded_rect)
        self.setMask(painter.clipRegion())
        painter.setOpacity(1.0)
        painter.fillPath(rounded_rect, QBrush(alpha_bgcolor))
        painter.restore()
        painter.end()
开发者ID:Schizo,项目名称:boxfish,代码行数:24,代码来源:ModuleFrame.py

示例7: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [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

示例8: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]
    def paintEvent(self, event):
        cX = self.parent.lytLeftMargin + self.scaleMarkLen
        cY = self.parent.lytTopMargin + self.scaleMarkLen
        worldX = self.parent.presenter.showChunkX*16
        worldZ = self.parent.presenter.showChunkZ*16
        painter = QPainter()
        path = QPainterPath()
        painter.begin(self)
        painter.save()
        #painter.setFont(QFont('Arial Narrow', 8)) #QFont.Bold
        # draw scale
        x = cX
        y = cY
        painter.rotate(-90)
        for i in range(16):
            fr = QRectF(-y, x, self.scaleMarkLen, self.edgeLen)
            painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, str(worldX))
            #painter.drawRect(fr)
            #fr = QRectF(-y - 16*self.edgeLen - self.scaleMarkLen, x, self.scaleMarkLen, self.edgeLen)
            #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
            #painter.drawRect(fr)
            x += self.edgeLen
            worldX += 1
        painter.rotate(90)

        x = self.parent.lytLeftMargin
        y = cY
        for i in range(16):
            fr = QRectF(x, y, self.scaleMarkLen, self.edgeLen)
            painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, str(worldZ))
            #painter.drawRect(fr)
            #fr = QRectF(x + self.scaleMarkLen + 16*self.edgeLen, y, self.scaleMarkLen, self.edgeLen)
            #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
            #painter.drawRect(fr)
            y += self.edgeLen
            worldZ += 1

        x = cX
        y = cY
        for i in range(16):
            for j in range(16):
                path.addRect(x, y, self.edgeLen, self.edgeLen)
                #fr = QRectF(x, y, self.edgeLen, self.edgeLen)
                #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
                x += self.edgeLen
            x = cX
            y += self.edgeLen
            
        painter.drawPath(path)

        slice_ = self.parent.presenter.getSlice(self.parent.presenter.elevation)
        x = cX
        y = cY
        bru = QBrush()
        #path1 = QPainterPath()
        for i in range(16):
            for j in range(16):
                if slice_[i][j] in self.parent.selectedMinerals.list_:
                    lePen = painter.pen()
                    
                    newPen = QPen(bru, 3)
                    newPen.setColor(self.parent.selectedMinerals.getColor(slice_[i][j]))
                    painter.setPen(newPen)
                    painter.drawRect(x, y, self.edgeLen, self.edgeLen)
                    painter.setPen(lePen)
                x += self.edgeLen
            x = cX
            y += self.edgeLen

        

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

示例9: Printer

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import save [as 别名]

#.........这里部分代码省略.........

    def emit_tps_report(self, employees):
        html = """
               <img
                   style="float: left;"
                   src=":/img/mmt.png"
                   width="200"
                   height="65">

               <h1 align="right">TPS Report<br /> </h1>
               <hr />
               """

        html += self.generate_sorted_employee_table(employees)
        self.make_page(html)

    def emit_sorted_employees(self, employees):
        html = """
               <img
                   style="float: left;"
                   src=":/img/mmt.png"
                   width="200"
                   height="65">

               <h1 align="right">All Employees sorted by Evalation Score<br />(highest to lowest)</h1>
               <hr />

               <table
                   align="center"
                   cellspacing="10">

                   <tr>
                       <th>ID</th>
                       <th>First Name</th>
                       <th>Last Name</th>
                       <th>Email Address</th>
                       <th>Phone Number</th>
                       <th>Cell Number</th>
                       <th>Overall Score</th>
                   </tr>
               """

        for employer, employee, score, comments in employees:
            html += """
                    <tr>
                        <td>%s</td>
                        <td>%s</td>
                        <td>%s</td>
                        <td>%s</td>
                        <td>%s</td>
                        <td>%s</td>
                        <td>%s</td>
                    </tr>
                    """ % (employee["id"],
                           employee["first_name"],
                           employee["last_name"],
                           employee["email_address"],
                           employee["phone_number"],
                           employee["cell_number"],
                           score)

        html += "</table>"
        self.make_page(html)

    def paper_mode(self):
        self.handler.setOutputFormat(QPrinter.NativeFormat)
        self.handler.setOutputFileName("")

    def pdf_mode(self, file_name):
        self.handler.setOutputFormat(QPrinter.PdfFormat)
        self.handler.setOutputFileName(file_name)

    def run(self):
        page_num  = 1
        last_page = len(self.pages)

        self.painter = QPainter(self.handler)

        for page in self.pages:
            width  = self.painter.viewport().width()
            height = self.painter.viewport().height()

            rect = QRect(0, 0, width, height)

            self.painter.save()
            self.painter.setViewport(rect)

            page.setTextWidth(width)

            page.drawContents(self.painter)

            self.painter.restore()

            if page_num != last_page:
                self.handler.newPage()

            page_num += 1

        self.painter.end()
        self.reset()
开发者ID:xiphffff,项目名称:Caerus,代码行数:104,代码来源:printer.py


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