Python PySide.QtGui.QPainter() Examples

The following are 8 code examples of PySide.QtGui.QPainter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySide.QtGui , or try the search function .
Example #1
Source File: CodeEditor.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: utils.py    From FreeCAD_assembly3 with GNU General Public License v3.0 5 votes vote down vote up
def getIcon(obj,disabled=False,path=None):
    if not path:
        path = iconPath
    if not getattr(obj,'_icon',None):
        obj._icon = addIconToFCAD(obj._iconName,path)
    if not disabled:
        return obj._icon
    if not getattr(obj,'_iconDisabled',None):
        name = getattr(obj,'_iconDisabledName',None)
        if name:
            obj._iconDisabled = addIconToFCAD(name,path)
        else:
            key = os.path.join(path,obj._iconName) + '.disabled'
            fmt = None
            try:
                if FreeCADGui.isIconCached(key):
                    obj._iconDisabled = key
                    return key
                else:
                    fmt = 'PNG'
            except Exception:
                pass
            pixmap = FreeCADGui.getIcon(obj._icon).pixmap(*iconSize,mode=QIcon.Disabled)
            icon = QIcon(pixmapDisabled)
            icon.paint(QPainter(pixmap),0,0,iconSize[0],iconSize[1],Qt.AlignCenter)
            data = QByteArray()
            buf = QBuffer(data)
            buf.open(QIODevice.WriteOnly)
            if fmt:
                pixmap.save(buf, fmt)
                FreeCADGui.addIcon(key,data.data(),fmt)
            else:
                pixmap.save(buf, 'XPM')
                key = data.data().decode('latin1')
            obj._iconDisabled = key
    return obj._iconDisabled 
Example #3
Source File: pyqt.py    From mgear_core with MIT License 5 votes vote down vote up
def get_icon(icon, size=24):
    """get svg icon from icon resources folder as a pixel map
    """
    img = get_icon_path("{}.svg".format(icon))
    svg_renderer = QtSvg.QSvgRenderer(img)
    image = QtGui.QImage(size, size, QtGui.QImage.Format_ARGB32)
    # Set the ARGB to 0 to prevent rendering artifacts
    image.fill(0x00000000)
    svg_renderer.render(QtGui.QPainter(image))
    pixmap = QtGui.QPixmap.fromImage(image)

    return pixmap 
Example #4
Source File: heatmap.py    From heatmappy with MIT License 5 votes vote down vote up
def _paint_points(self, img, points):
        painter = QtGui.QPainter(img)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 0))
        pen.setWidth(0)
        painter.setPen(pen)

        for point in points:
            self._paint_point(painter, *point)
        painter.end() 
Example #5
Source File: QtShim.py    From grap with MIT License 5 votes vote down vote up
def get_QPainter():
    """QPainter getter."""

    try:
        import PySide.QtGui as QtGui
        return QtGui.QPainter
    except ImportError:
        import PyQt5.QtGui as QtGui
        return QtGui.QPainter 
Example #6
Source File: LNTextEdit.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def numberbarPaint(self, number_bar, event):
            font_metrics = self.fontMetrics()
            current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
 
            block = self.firstVisibleBlock()
            line_count = block.blockNumber()
            painter = QtGui.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.blockBoundingGeometry(block).translated(self.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)
                    painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)
 
                # Draw the line number right justified at the position of the line.
                paint_rect = QtCore.QRect(0, block_top, number_bar.width(), font_metrics.height())
                painter.drawText(paint_rect, QtCore.Qt.AlignRight, unicode(line_count))
 
                block = block.next()
 
            painter.end() 
Example #7
Source File: LNTextEdit_v3.2.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def numberbarPaint(self, number_bar, event):
            font_metrics = self.fontMetrics()
            current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
 
            block = self.firstVisibleBlock()
            line_count = block.blockNumber()
            painter = QtGui.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.blockBoundingGeometry(block).translated(self.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)
                    painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)
 
                # Draw the line number right justified at the position of the line.
                paint_rect = QtCore.QRect(0, block_top, number_bar.width(), font_metrics.height())
                painter.drawText(paint_rect, QtCore.Qt.AlignRight, unicode(line_count))
 
                block = block.next()
 
            painter.end() 
Example #8
Source File: bar_widget.py    From tdoa with Apache License 2.0 5 votes vote down vote up
def paintEvent(self, e):

        painter = QtGui.QPainter()
        painter.begin(self)
        self.drawBars(painter)
        painter.end()