示例#1
0
    def drawIconWithShadow(icon, rect, p, iconMode, radius, color, offset):
        cache = QPixmap()
        pixmapName = "icon {0} {1} {2}".format(icon.cacheKey(), iconMode, rect.height())

        if not QPixmapCache.find(pixmapName, cache):
            px = icon.pixmap(rect.size())
            cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
            cache.fill(Qt.transparent)

            cachePainter = QPainter(cache)
            if iconMode == QIcon.Disabled:
                im = px.toImage().convertToFormat(QImage.Format_ARGB32)
                for y in range(im.height()):
                    scanLine = im.scanLine(y)
                    for x in range(im.width()):
                        pixel = scanLine
                        intensity = qGray(pixel)
                        scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel))
                        scanLine += 1
                px = QPixmap.fromImage(im)

            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1), QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(QPoint(radius, radius), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            # todo : blur image
            blurPainter.end()

            tmp = blurred

            # blacken the image
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp)

            # Draw the actual pixmap...
            cachePainter.drawPixmap(QPoint(radius, radius) + offset, px)
            QPixmapCache.insert(pixmapName, cache)

        targetRect = cache.rect()
        targetRect.moveCenter(rect.center())
        p.drawPixmap(targetRect.topLeft() - offset, cache)
示例#2
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.fillRect(event.rect(), Qt.white)
        painter.setFont(self.displayFont)

        redrawRect = event.rect()
        beginRow = redrawRect.top() // self.squareSize
        endRow = redrawRect.bottom() // self.squareSize
        beginColumn = redrawRect.left() // self.squareSize
        endColumn = redrawRect.right() // self.squareSize

        painter.setPen(Qt.gray)
        for row in range(beginRow, endRow + 1):
            for column in range(beginColumn, endColumn + 1):
                painter.drawRect(column * self.squareSize,
                                 row * self.squareSize, self.squareSize,
                                 self.squareSize)

        fontMetrics = QFontMetrics(self.displayFont)
        painter.setPen(Qt.black)
        for row in range(beginRow, endRow + 1):
            for column in range(beginColumn, endColumn + 1):
                char = chr(row * COLUMNS + column)
                painter.setClipRect(column * self.squareSize,
                                    row * self.squareSize, self.squareSize,
                                    self.squareSize)
                if char == self.currentChar:
                    painter.fillRect(column * self.squareSize + 1,
                                     row * self.squareSize + 1,
                                     self.squareSize, self.squareSize,
                                     Qt.green)
                painter.drawText(
                    column * self.squareSize + (self.squareSize / 2) -
                    fontMetrics.width(char) / 2,
                    row * self.squareSize + 4 + fontMetrics.ascent(), char)
示例#3
0
文件: lines.py 项目: hofoen/pcef-core
 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)
示例#4
0
    def __init__(self, parent, scene, view):
        super(QNodesEditor, self).__init__(parent)

        self.scene = scene
        self.scene.installEventFilter(self)

        gridSize = 25
        gridMap = QPixmap(gridSize,gridSize)
        gridPainter = QPainter(gridMap)
        gridPainter.fillRect(0,0,gridSize,gridSize, QApplication.palette().window().color().darker(103))
        gridPainter.fillRect(1,1,gridSize-2,gridSize-2, QApplication.palette().window())
        gridPainter.end()
        self.scene.setBackgroundBrush( QBrush(gridMap) )

        originSize = 50
        originItem = QGraphicsPathItem()
        path = QPainterPath()
        path.moveTo(0,-originSize)
        path.lineTo(0,originSize)
        path.moveTo(-originSize,0)
        path.lineTo(originSize,0)
        originItem.setPath(path)
        originItem.setPen(QPen(QApplication.palette().window().color().darker(110),2))
        originItem.setZValue(-2)
        self.scene.addItem(originItem)

        self.view = view
        self.view.setDragMode(QGraphicsView.RubberBandDrag)
        self.view.setRenderHint(QPainter.Antialiasing)

        self.connection = None
示例#5
0
    def paintEvent(self, e):
        painter = QPainter()
        painter.begin(self)
        
        width = self.width()
        height = self.height()
        
        #Blank out the world
        painter.fillRect(0, 0, width, height, Qt.white)

        #Compute width/height of the columns and rows
        
        #Reserve pixels for the grid lines
        colWidth = (width - (self._NUM_COLS - 1) * self._GRID_SIZE) / self._NUM_COLS
        rowHeight = (height - (self._NUM_ROWS - 1) * self._GRID_SIZE) / self._NUM_ROWS
        
        colWidth = max(1, colWidth)
        rowHeight = max(1, rowHeight)

        #Perform drawing operations for world rendering
        self._drawGrid(width, height, colWidth, rowHeight, painter)
        self._drawObstacles(colWidth, rowHeight, painter)
        if self._drawVisited:
            self._drawVisitedCells(colWidth, rowHeight, painter)
        if self._drawActive:
            self._drawActiveCells(colWidth, rowHeight, painter)
        self._drawStartAndEndCells(colWidth, rowHeight, painter)
        self._drawCurrentCell(colWidth, rowHeight, painter)
        if self._drawCheapestPath:
            self._drawPath(colWidth, rowHeight, painter)
        
        painter.end()
示例#6
0
def SetImageTransparency(image, transparencyPercentage):
    """ Set the Image Transparency to the value provided """
    alpha = QImage(image)
    painter = QPainter(alpha)
    alphaValue = int(transparencyPercentage*255/100)
    painter.fillRect(alpha.rect(), QColor(alphaValue, alphaValue, alphaValue))
    painter.end()
    image.setAlphaChannel(alpha)
示例#7
0
def SetImageTransparency(image, transparencyPercentage):
    """ Set the Image Transparency to the value provided """
    alpha = QImage(image)
    painter = QPainter(alpha)
    alphaValue = int(transparencyPercentage * 255 / 100)
    painter.fillRect(alpha.rect(), QColor(alphaValue, alphaValue, alphaValue))
    painter.end()
    image.setAlphaChannel(alpha)
示例#8
0
    def numberbarPaint(self, number_bar, event):
        """Paints the line numbers of the code file"""
        self.number_bar.link = []
        font_metrics = self.getWidget().fontMetrics()
        current_line = self.getWidget().document().findBlock(
            self.getWidget().textCursor().position()).blockNumber() + 1

        block = self.getWidget().firstVisibleBlock()
        line_count = block.blockNumber()
        painter = QPainter(self.number_bar)
        # TODO: second argument is color -> to settings
        painter.fillRect(self.number_bar.rect(),
                         self.getWidget().palette().base())

        # Iterate over all visible text blocks in the document.
        while block.isValid():
            line_count += 1
            text = str(line_count)
            block_top = self.getWidget().blockBoundingGeometry(
                block).translated(self.getWidget().contentOffset()).top()
            if not block.isVisible():
                block = block.next()
                while not block.isVisible():
                    line_count += 1
                    block = block.next()
                continue
            self.number_bar.link.append((block_top, line_count))
            # Check if the position of the block is out side of the visible
            # area.
            if 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)

            else:
                font = painter.font()
                font.setBold(False)
            # line opens a block
            if line_count in self.hidden:
                text += "+"
                font.setUnderline(True)
            elif block.text().count("(") > block.text().count(")"):
                text += "-"
                font.setUnderline(True)
            else:
                font.setUnderline(False)
            painter.setFont(font)
            # Draw the line number right justified at the position of the
            # line.
            paint_rect = QRect(0, block_top, self.number_bar.width(),
                               font_metrics.height())
            painter.drawText(paint_rect, Qt.AlignLeft, text)
            block = block.next()

        painter.end()
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
    def paintEvent(self, event):
        """ Paints the widget """
        if self.enabled is False:
            return
        Panel.paintEvent(self, event)
        painter = QPainter(self)
        painter.fillRect(event.rect(), self.back_brush)

        for vb in self.editor.codeEdit.visible_blocks:
            line = vb.row
            # paint marker for line
            marker = self.getIndicatorForLine(line)
            if marker is None:
                continue
                # use the normal pen to draw the fold indicator
            drawLines = False
            pen = self.normal_pen
            if marker.hover is True:
                pen = self.highlight_pen
                drawLines = True
            painter.setPen(pen)
            # get the text to draw
            txt = '-'
            if marker.folded is True:
                drawLines = False
                txt = '+'
            offset = 4
            h = self.size_hint.height()
            fm = QFontMetricsF(self.editor.codeEdit.font())
            hoffset = (fm.height() - h) / 2.0
            r = QRect(vb.rect.x(), vb.rect.y() + hoffset, self.size_hint.width(), self.size_hint.height())
            painter.setFont(self.font)
            painter.drawText(r, Qt.AlignVCenter | Qt.AlignHCenter, txt)
            w = self.size_hint.width() - 2 * offset
            h = self.size_hint.width() - 2 * offset
            hoffset = (fm.height() - h) / 2.0
            r.setX(vb.rect.x() + offset)
            r.setY(vb.rect.y() + hoffset)
            r.setWidth(w)
            r.setHeight(h)
            painter.drawRect(r)
            if drawLines is True:
                top = (vb.rect.x() + self.size_hint.width() / 2.0,
                       vb.rect.y() + hoffset + offset * 2)
                delta = ((marker.end - marker.start) * vb.height)  # - (vb.rect.height() / 2.0)
                bottom = (top[0], top[1] + delta)
                painter.drawLine(top[0], top[1], bottom[0], bottom[1])
                painter.drawLine(bottom[0], bottom[1], bottom[0] + self.size_hint.width() / 2.0, bottom[1])

        return
示例#12
0
    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`AboutDialog`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        rect = self.rect()

        painter = QPainter(self)
        painter.setRenderHint(painter.SmoothPixmapTransform)

        # Always fill with a solid color first
        painter.fillRect(rect, Qt.white)

        # Then overlay the texture
        painter.fillRect(rect, self.bgBrush)
示例#13
0
    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`AboutDialog`.

        :param `event`: a `QPaintEvent` event to be processed.
        """
        rect = self.rect()

        painter = QPainter(self)
        painter.setRenderHint(painter.SmoothPixmapTransform)

        # Always fill with a solid color first
        painter.fillRect(rect, Qt.white)

        # Then overlay the texture
        painter.fillRect(rect, self.bgBrush)
示例#14
0
文件: gui.py 项目: johnjohnsp1/hrdev
        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
示例#15
0
文件: gui.py 项目: 453483289/hrdev
        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
示例#16
0
文件: qimp.py 项目: Rougnt/VNR-Core
def gradientpixmap(pm):
  """
  @param  pm  QPixmap
  @return  QPixmap
  """
  # http://www.qtcentre.org/threads/4246-QGraphicsPixmapItem-modifying-the-alpha-channel-of-a-QPixmap
  # http://www.qtcentre.org/threads/37866-QPainter-fill-rect-with-gradient
  if not pm.isNull():
    w = pm.width()
    h = pm.height()
    if w and h:
      gr = getgradient(0, 0, w, h)
      #gr = QLinearGradient(alpha.rect().topLeft(), alpha.rect().bottomRight())
      alpha = QPixmap(w, h)
      p = QPainter(alpha)
      p.fillRect(alpha.rect(), gr)
      p.end()
      pm.setAlphaChannel(alpha)
示例#17
0
 def paintEvent(self, event):
     """ Paints the widget """
     if self.enabled is False:
         return
     Panel.paintEvent(self, event)
     painter = QPainter(self)
     painter.fillRect(event.rect(), self.back_brush)
     for vb in self.editor.codeEdit.visible_blocks:
         l = vb.row
         marker = self.__getMarkerForLine(l)
         if marker:
             if marker.icon is not None:
                 r = QRect()
                 r.setX(vb.rect.x())
                 r.setY(vb.rect.y())
                 r.setWidth(self.size_hint.width())
                 r.setHeight(self.size_hint.height())
                 marker.icon.paint(painter, r)
     return
示例#18
0
    def addUnit(self, unit):
        global mapSize
        unit.tile = self
        self.units.append(unit)
        img = QImage(unit.image).scaledToWidth(self.getImageRect().width())
        if unit.owner:
            rect = img.rect()
            painter = QPainter(img)
            painter.setPen(unit.owner.unitColor())
            painter.drawEllipse(rect)

            hpWidth = 20
            greenWidth = unit.hp / float(unit.maxHp) * hpWidth
            painter.fillRect(5, 5, greenWidth, 5, Qt.green)
            painter.fillRect(5 + greenWidth, 5, hpWidth-greenWidth, 5, Qt.red)
            painter.end()
        image = QGraphicsPixmapItem(QPixmap(img), self)
        if mapSize == 0:
            mapSize = 1
        image.setOffset(self.x + 12/(2*mapSize), self.y + 10/(2*mapSize))
        self.unitImages.append(image)
示例#19
0
    def lineNumberAreaPaintEvent(self, event):
        painter = QPainter(self.lineNumberArea)
        painter.fillRect(event.rect(), Qt.lightGray)

        block = self.firstVisibleBlock()
        blockNumber = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(
            self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()

        while (block.isValid() and top <= event.rect().bottom()):
            if (block.isValid and bottom >= event.rect().top()):
                number = str(blockNumber + 1)
                painter.setPen(QtCore.Qt.black)
                painter.drawText(0, top, self.lineNumberArea.width(),
                                 self.fontMetrics().height(),
                                 QtCore.Qt.AlignCenter, number)
            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            blockNumber += 1
示例#20
0
    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`MdiArea`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        vport = self.viewport()
        rect = vport.rect()

        painter = QPainter(vport)
        painter.setRenderHint(painter.SmoothPixmapTransform)

        # Always fill with a solid color first
        if self.useColor:
            # painter.fillRect(rect, self.colorBrush)
            painter.fillRect(rect, self.bgColor)
        else:
            painter.fillRect(rect, self.background())

        # Then overlay the texture
        if self.useTexture:
            # painter.fillRect(rect, self.backgroundBrush)
            bgBrush = QBrush(self.bgTexture)
            painter.fillRect(rect, bgBrush)
            

        # Overlay the logo last
        if self.useLogo:
            if not len(self.subWindowList()):  # Nothing is open.
                cSizeW, cSizeH = rect.width(), rect.height()
                bgLogoW, bgLogoH = self.bgLogo.width(), self.bgLogo.height()
                if bgLogoW > cSizeW:
                    # Proportional Scaling an Image.
                    newHeight = bgLogoH * cSizeW // bgLogoW
                    scaledLogo = self.bgLogo.scaled(cSizeW, newHeight)
                    painter.drawPixmap(0,
                                       cSizeH // 2 - scaledLogo.height() // 2,
                                       scaledLogo)
                else:
                    painter.drawPixmap((cSizeW - bgLogoW) // 2,
                                       (cSizeH - bgLogoH) // 2,
                                       self.bgLogo)
            else:
                # Center the pixmap
                dx = (rect.width() - self.bgLogo.width()) / 2
                dy = (rect.height() - self.bgLogo.height()) / 2
                painter.drawPixmap(dx, dy,
                                   self.bgLogo.width(), self.bgLogo.height(),
                                   self.bgLogo)
示例#21
0
    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`MdiArea`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        vport = self.viewport()
        rect = vport.rect()

        painter = QPainter(vport)
        painter.setRenderHint(painter.SmoothPixmapTransform)

        # Always fill with a solid color first
        if self.useColor:
            # painter.fillRect(rect, self.colorBrush)
            painter.fillRect(rect, self.bgColor)
        else:
            painter.fillRect(rect, self.background())

        # Then overlay the texture
        if self.useTexture:
            # painter.fillRect(rect, self.backgroundBrush)
            bgBrush = QBrush(self.bgTexture)
            painter.fillRect(rect, bgBrush)

        # Overlay the logo last
        if self.useLogo:
            if not len(self.subWindowList()):  # Nothing is open.
                cSizeW, cSizeH = rect.width(), rect.height()
                bgLogoW, bgLogoH = self.bgLogo.width(), self.bgLogo.height()
                if bgLogoW > cSizeW:
                    # Proportional Scaling an Image.
                    newHeight = bgLogoH * cSizeW // bgLogoW
                    scaledLogo = self.bgLogo.scaled(cSizeW, newHeight)
                    painter.drawPixmap(0,
                                       cSizeH // 2 - scaledLogo.height() // 2,
                                       scaledLogo)
                else:
                    painter.drawPixmap((cSizeW - bgLogoW) // 2,
                                       (cSizeH - bgLogoH) // 2, self.bgLogo)
            else:
                # Center the pixmap
                dx = (rect.width() - self.bgLogo.width()) / 2
                dy = (rect.height() - self.bgLogo.height()) / 2
                painter.drawPixmap(dx, dy, self.bgLogo.width(),
                                   self.bgLogo.height(), self.bgLogo)
示例#22
0
    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)
        painter.fillRect(event.rect(), self.color)
示例#23
0
def paint_redock_overlay(widget):
    painter = QPainter(widget)
    brush = QBrush(QApplication.palette().color(QPalette.Highlight),
                   Qt.Dense6Pattern)
    painter.fillRect(widget.rect(), brush)
示例#24
0
文件: accd.py 项目: Sugz/Python
    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:
            if self.isCollapsed():
                arect = QRect(x + 1, y + 9, w - 1, 4)
                brect = QRect(x, y + 8, w - 1, 4)
                text = '+'
            else:
                arect = QRect(x + 1, y + 9, w - 1, h - 9)
                brect = QRect(x, y + 8, w - 1, h - 9)
                text = '-'

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

            painter.drawRect(arect)

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

            painter.drawRect(brect)

            painter.setRenderHint(painter.Antialiasing, False)
            painter.setBrush(self.palette().color(QPalette.Window).darker(120))
            painter.drawRect(x + 10, y + 1, w - 20, 16)
            painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text)
            painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title())

        if self.dragDropMode():
            rect = self.dragDropRect()

            # draw the lines
            l = rect.left()
            r = rect.right()
            cy = rect.center().y()

            for y in (cy - 3, cy, cy + 3):
                painter.drawLine(l, y, r, y)

        painter.end()
示例#25
0
 def paintEvent(self, event):
     p = QPainter()
     p.begin(self)
     p.fillRect(self.rect(), QBrush(QColor(240, 200, 0)))
     p.end()
示例#26
0
 def paintEvent(self, event):
     p = QPainter()
     p.begin(self)
     p.fillRect(self.rect(), QBrush(QColor(240, 200, 0)))
     p.end()
示例#27
0
    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)
        painter.fillRect(event.rect(), self.color)