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


Python QPainter.drawRect方法代码示例

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


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

示例1: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
    def paintEvent(self, event):
        paintRegion = event.region()
        painter = QPainter(self)
        pal = self.palette()

        for shape in self._shapeList:
            rect = shape.rect
            
            if not paintRegion.contains(rect):
                continue
            
            shapeType = shape.type
            
            painter.setBrush(shape.color)
            
            if shapeType == ShapeType.Rectangle:
                print "rectangle"
                painter.drawRect(rect)
            elif shapeType == ShapeType.Circle:
                print "circle"
                painter.drawEllipse(rect)
            
            # paint the shape name
            painter.setBrush(pal.text())
            painter.drawText(rect, Qt.AlignCenter, shape.name)
开发者ID:satishgoda,项目名称:learningqt,代码行数:27,代码来源:document.py

示例2: paintEvent

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

示例3: paint

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
    def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()

        if is_secondary_color:
            pen.setColor(self.data_singleton.secondary_color)
        else:
            pen.setColor(self.data_singleton.primary_color)

        painter = QPainter(canvas.image)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        painter.setPen(pen)

        if is_secondary_color:
            painter.setBrush(self.data_singleton.primary_color)
        else:
            painter.setBrush(self.data_singleton.secondary_color)

        if self._start_point != self._end_point:
            painter.drawRect(QRect(self._start_point, self._end_point))

        painter.end()

        canvas.edited = True
        canvas.update()
开发者ID:gil9red,项目名称:fake-painter,代码行数:31,代码来源:rectangleinstrument.py

示例4: paintEvent

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

示例5: paintEvent

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

示例6: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     painter.setRenderHint(QPainter.HighQualityAntialiasing)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setRenderHint(QPainter.SmoothPixmapTransform)
     painter.setBrush(QColor(self.color))
     painter.drawRect(self.window().x() + 4, self.window().y() + 4, self.window().width(), self._height)
     painter.end()
开发者ID:ethanhs,项目名称:material,代码行数:11,代码来源:material.py

示例7: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
 def paintEvent(self, paintEvent):
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.scale(self.scale, self.scale)
     painter.drawRect(0, 0, 511, 511)
     painter.drawImage(0, 0, self.image)
     if self.freeze_image is not None and self.freeze_image is not self.image:
         painter.setOpacity(0.3)
         painter.drawImage(0, 0, self.freeze_image)
开发者ID:NateShoffner,项目名称:PySnip-Map-Editor,代码行数:11,代码来源:run.py

示例8: paintEvent

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

示例9: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
    def paintEvent(self, e):
        painter = QPainter(self)
        painter.setWorldTransform(QTransform().scale(0.5, 0.5))

        x = 0

        for i in self.images:
            painter.drawImage(QRect(x, 0, i.width(), i.height()), i)
            painter.drawRect(x, 0, i.width(), i.height())
            x += i.width()
开发者ID:Ingener74,项目名称:Silly-Crossbow,代码行数:12,代码来源:AberrantTiger.py

示例10: draw

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
    def draw(self, endPoint_x, endPoint_y):
        painter = QPainter(self.image)

        painter.setPen(QPen(
            self.myPenColor, self.myPenWidth, QtCore.Qt.SolidLine,
            QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        painter.setClipping(True)

        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setCompositionMode(QPainter.CompositionMode())

        if self.tools['circle']:
            x1 = self.firstPoint_x
            y1 = self.firstPoint_y
            x2 = endPoint_x
            y2 = endPoint_y
            painter.drawEllipse(x1, y1, (x2 - x1), (y2 - y1))

        if self.tools['eraser']:
            painter.setPen(QPen(QtCore.Qt.white, 10, QtCore.Qt.SolidLine))
            painter.drawLine(
                self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
            self.firstPoint_x = endPoint_x
            self.firstPoint_y = endPoint_y

        if self.tools['pen']:
            painter.drawLine(
                self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
            self.firstPoint_x = endPoint_x
            self.firstPoint_y = endPoint_y

        if self.tools['line'] and self.flag:
            painter.drawLine(
                self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)

        if self.tools['rect']:
            dx = endPoint_x - self.firstPoint_x
            dy = endPoint_y - self.firstPoint_y
            painter.drawRect(self.firstPoint_x, self.firstPoint_y, dx, dy)

        if self.tools['roundRect']:
            x1 = self.firstPoint_x
            y1 = self.firstPoint_y
            dx = endPoint_x - self.firstPoint_x
            dy = endPoint_y - self.firstPoint_y
            if x1 > endPoint_x and y1 > endPoint_y:
                painter.drawRoundedRect(
                    endPoint_x, endPoint_y, -dx, -dy, 20, 20, 0)
            else:
                painter.drawRoundedRect(x1, y1, dx, dy, 20., 20.)

        self.modified = True
        self.update()
开发者ID:pouzzler,项目名称:IED-Logic-Simulator,代码行数:57,代码来源:circuitdrawing.py

示例11: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`SelectBox`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        painter = QPainter(self)
        painter.setPen(self._dirPen)
        width, height = self.width(), self.height()
        painter.fillRect(0, 0, width - 1, height - 1, self._dirBrush)
        painter.drawRect(0, 0, width - 1, height - 1)
开发者ID:Metallicow,项目名称:Embroidermodder,代码行数:13,代码来源:selectbox.py

示例12: draw_marker

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
    def draw_marker(self, x, y, pixmap, scale):
        "Draw the brush marker indicating what area will be painted"

        w, h = self.size*scale, self.size*scale
        painter = QPainter(pixmap)

        painter.setPen(Qt.green)
        painter.drawRect(x - w/2, y - h/2, w, h)

        x = pixmap.width() - x
        y = pixmap.height() - y
        painter.drawRect(x - w/2, y - h/2, w, h)
开发者ID:fredo-editor,项目名称:FreDo,代码行数:14,代码来源:square_brush.py

示例13: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
    def paintEvent(self, evt):
        # print 'paint', self.color, self.text(), self.width(), self.height(), evt.rect().width()
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(QColor('#{}'.format(self.color[:-2])))
        qp.drawRect(0, 0, self.width(), self.height())
        qp.end()

        qp.begin(self)
        qp.setPen(self._get_text_color())
        qp.drawText(evt.rect(), QtCore.Qt.AlignCenter, self.text())
        qp.end()
开发者ID:OSUPychron,项目名称:pychron,代码行数:14,代码来源:label_editor.py

示例14: paintEvent

# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawRect [as 别名]
 def paintEvent(self,e):
     
     painter = QPainter(self)
     
     for rect in self.rectangles:
         try:
             xa,ya,xb,yb = rect
             
             rect = xa,ya,xb-xa,yb-ya
             painter.setBrush(randomColor())
             painter.drawRect(QRect(*rect))
         except:
             print('rect was foul')
开发者ID:AnjoMan,项目名称:PyTreeMap,代码行数:15,代码来源:Treemap.py

示例15: paintEvent

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

		painter.setBrush(Qt.white)
		painter.drawRect(self.rect())

		painter.translate(self.width()/2, self.height()/2)

		if self.pixReady:
			grammarPix = QPixmap("/tmp/grammar.png")
			pw = grammarPix.width()
			ph = grammarPix.height()
			painter.drawPixmap(-pw/2, -ph/2, grammarPix)
开发者ID:omartinak,项目名称:cfree,代码行数:15,代码来源:paintArea.py


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