Esempio n. 1
0
	def paintEvent(self, painteevent):
		painter = QPainter(self)

		painter.setRenderHint(QPainter.Antialiasing)

		for obj in self.objects:
			obj.paint(painter)
Esempio n. 2
0
    def paintEvent(self, e):
        'Custom Paint Event'
        p = QPainter(self)
        
        opt = QStyleOptionFrameV3()
        opt.initFrom(self)
        opt.rect = self.contentsRect()
        opt.lineWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth, opt, self)
        opt.midLineWidth = 0
        opt.state = opt.state | QStyle.State_Sunken
        
        if self._active:
            opt.state = opt.state | QStyle.State_HasFocus
        else:
            opt.state = opt.state & ~QStyle.State_HasFocus;
        
        self.style().drawPrimitive(QStyle.PE_PanelLineEdit, opt, p)

        y = (opt.rect.height() - self._star.height()) / 2 
        width = self._star.width()
        
        for i in range(0, 5):
            x = i*(width + 1) + opt.lineWidth
            
            if self._rating >= i+0.5:
                p.drawImage(x, y, self._star if not self._active else self._blue)
            else:
                p.drawImage(x, y, self._dot)
 def paintEvent(self, pe):
   painter = QPainter(self) 
   if self._fill:
     scaled_pixmap = self._image_pixmap.scaled(self.size(), Qt.IgnoreAspectRatio)
     painter.drawPixmap(0, 0, scaled_pixmap)
   else:
     painter.drawPixmap(0, 0, self._image_pixmap)
Esempio n. 4
0
    def set_clipboard_image(self):
        """Export the formatted output to an image and store it in the
        clipboard.

        The image stored in the clipboard is a PNG file with alpha
        transparency.

        """
        div = self.view.page().mainFrame().findFirstElement('.output')
        images = {}
        for background in (Qt.transparent, Qt.white):
            image = QImage(div.geometry().size(),
                           QImage.Format_ARGB32_Premultiplied)
            image.fill(background)
            painter = QPainter(image)
            div.render(painter)
            painter.end()
            images[background] = image

        # Windows needs this buffer hack to get alpha transparency in
        # the copied PNG.
        buffer_ = QBuffer()
        buffer_.open(QIODevice.WriteOnly)
        images[Qt.transparent].save(buffer_, 'PNG')
        buffer_.close()
        data = QMimeData()
        data.setData('PNG', buffer_.data())
        data.setImageData(images[Qt.white])
        QApplication.clipboard().setMimeData(data)
Esempio n. 5
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)
Esempio n. 6
0
 def paint(self, painter, option, widget=None):
     painter_inverted = QPainter()
     brect= QGraphicsProxyWidget.boundingRect(self)
     invertedColor = QImage(brect.width(),brect.height(),QImage.Format_RGB32)
     painter_inverted.begin(invertedColor)
     QGraphicsProxyWidget.paint(self,painter_inverted, option, widget)
     painter_inverted.end()
     painter.drawImage(0,0,invertedColor.rgbSwapped())
    def resizeImage(self, image, newSize):
        if image.size() == newSize:
            return
        newImage = QImage(newSize, QImage.Format_RGB32)
        newImage.fill(qRgb(255, 255, 255))
        painter = QPainter(newImage)
        painter.drawImage(QtCore.QPoint(0, 0), image)

        self.image = newImage
Esempio n. 8
0
    def capture(self, filename):
        image = QImage(self._view.page().currentFrame().contentsSize(), QImage.Format_ARGB32)

        painter = QPainter(image)

        self._view.page().currentFrame().render(painter)
        painter.end()

        image.save(filename)
Esempio n. 9
0
 def _update_cursor(self):
     x = self.diameter
     w, h = x, x
     pixmap = QPixmap(w, h)
     pixmap.fill(Qt.transparent)
     p = QPainter(pixmap)
     p.drawPoints(self._points)
     p.end()
     self._cursor_pixmap = pixmap.createMaskFromColor(Qt.transparent)
 def paintEvent(self, pe):
   if self._mouse_over:
     icon = self._hover_icon
   else:
     icon = self._normal_icon
   painter = QPainter(self)
   pixmap = QPixmap(icon)
   pixmap = pixmap.scaled(self.size(), Qt.IgnoreAspectRatio)
   painter.drawPixmap(0, 0, pixmap)
 def paintEvent(self, pe):
   super(ProgressLineEdit, self).paintEvent(pe)
   painter = QPainter(self)
   painter.setOpacity(self.property("_progress_opacity"))
   sopb = QStyleOptionProgressBarV2()
   sopb.minimum = 0
   sopb.maximum = 100
   sopb.progress = self._progress
   sopb.initFrom(self)
   self.style().drawControl(QStyle.CE_ProgressBarContents, sopb, painter, self)
    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`ImageWidget`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        painter = QPainter(self)
        painter.drawPixmap(0, 0, self.pixmap)
        if self.parent.lightswitch.isOn: # Turn the light on.
            painter.drawImage(self.size().width() - 113, 1, self.lightOnImg)
Esempio n. 13
0
	def paintEvent(self, event):
		painter = QPainter()

		painter.begin(self)

		self.theme.render(painter, "kdiamond-" + self.color)
		if self.selected:
			self.theme.render(painter, "kdiamond-selection")

		painter.end()
Esempio n. 14
0
    def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

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

        painter = QPainter(canvas.image)
        painter.setPen(pen)

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

        if self._start_point == self._end_point:
            painter.drawPoint(self._start_point)

        painter.end()

        canvas.edited = True
        canvas.update()
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setWorldTransform(QTransform().scale(self.scale, self.scale))

        for i, b in enumerate(self.bins):
            side = int(math.ceil(math.log(len(self.bins), 2)))

            x = (i % side) * (b.size.width + 10) if side else 10
            y = (i / side) * (b.size.height + 10) if side else 10

            b.draw(painter, Point(x, y))
Esempio n. 16
0
 def paintEvent(self, e):
     ''' overwrite paintEvent in order to also redraw points (indicating
     electrode positions) and their link to added plots
     
     this is necessary to get smooth animation if plots are dragged around
     '''
     super(DragWindow, self).paintEvent(e)
     qp = QPainter()
     qp.begin(self)
     self.drawPoints(qp)
     qp.end()
Esempio n. 17
0
    def x_bitmap_opaque ( self, bitmap ):
        """ Returns a version of the specified bitmap with no transparency.
        """
        dx = bitmap.width()
        dy = bitmap.height()
        opaque_bitmap = QPixmap( dx, dy )
        opaque_bitmap.fill( WindowColor )
        q = QPainter( opaque_bitmap )
        q.drawPixmap( 0, 0, bitmap )

        return opaque_bitmap
Esempio n. 18
0
    def print_(self):
        canvas = self.mw.get_current_canvas()
        if not canvas:
            return

        printer = QPrinter()
        dlg = QPrintDialog(printer, self.mw)
        if dlg.exec_() == QDialog.Accepted:
            painter = QPainter(printer)
            painter.drawImage(0, 0, canvas.image)
            painter.end()
Esempio n. 19
0
    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`EmbroidermodderLogo`.

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

        painter.drawPixmap(0, 0, self.pixmap)
        # Draw the overlays.
        if self.paintThisText == 'About':
            painter.drawPixmap(20, 15, self.pixmap1ForPaintEvent)
Esempio n. 20
0
 def __paintMargin(self, event):
     """ Paints the right margin as postPainting step. """
     rect = event.rect()
     font = self.editor.codeEdit.currentCharFormat().font()
     fm = QFontMetricsF(font)
     pos = self.marginPos
     offset = self.editor.codeEdit.contentOffset().x() + \
              self.editor.codeEdit.document().documentMargin()
     x80 = round(fm.width(' ') * pos) + offset
     p = QPainter(self.editor.codeEdit.viewport())
     p.setPen(self.pen)
     p.drawLine(x80, rect.top(), x80, rect.bottom())
Esempio n. 21
0
 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')
    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()
 def takeScreenshot(self):        
     [x,y,width,height] = self.image_crop
     frame = self.page().mainFrame()
     size = frame.contentsSize()
     size.setWidth(1000)
     size.setHeight(2000)
     self.page().setViewportSize(size)
     image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
     painter = QPainter(image)
     frame.render(painter)
     painter.end()
     image1 = image.copy(x,y,width,height)
     image1.save(self.fileName)
     self.finished = True
Esempio n. 24
0
 def paintEvent(self, event):
     QToolButton.paintEvent(self, event)
     p = QPainter(self)
     p.setRenderHint(QPainter.TextAntialiasing)
     p.setRenderHint(QPainter.Antialiasing)
     if self.badge_counter > 0x00:
         point = self.rect().topRight()
         self.drawBadge(
             p,
             point.x() - self.badge_size,
             point.y(),
             self.badge_size,
             str(self.badge_counter),
             QBrush(self.redGradient),
             )
Esempio n. 25
0
    def saveAsPDF(self):
        '''Save plot as a PDF'''
        if not self.control.hasPlot:
            error.showMessage('Cannot save.. there is no data to save yet')
            return
        filter = 'PDF Documents (*.pdf);;All (*)'
        d = '' if self.pdfName is None else self.pdfName
        s = QFileDialog.getSaveFileName(self, 'PDF File Name',
                                              d, filter)
        # Continue unless the user hit cancel
        if not s[0]:
            return
        self.pdfName = s[0]

        # Set up the PDF printer
        printer = QPrinter()
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOrientation(QPrinter.Landscape)
        printer.setOutputFileName(self.pdfName)
        printer.setCreator('RAPID')

        # Send to the plot for printing
        p = QPainter()
        p.begin(printer)
        x, y = self.plot.calculatedData()
        plt = pgplot(x, y,
                     antialias=True,
                     connect='all',
                     pen={'color': 'b', 'width': 0})
        plt.setLabel('bottom', "Frequency (Wavenumbers, cm<sup>-1</sup>)")
        plt.getAxis('bottom').setPen('k')
        plt.setLabel('left', "Intensity (Normalized)")
        plt.getAxis('left').setPen('k')
        plt.setYRange(0, 1.1, padding=0)
        plt.invertX(self.plot.reversed)
        plt.setBackground('w')  # White

        # The raw (experimental) data, if any
        if self.plot.rawData is not None:
            data = self.plot.getRawData()
            x, y = data[:,0], data[:,1]
            curve2 = PlotCurveItem(x, y,
                                   antialias=True,
                                   connect='all',
                                   pen={'color': 'g', 'width': 0})
            plt.addItem(curve2)
        plt.render(p)
        p.end()
Esempio n. 26
0
    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()
Esempio n. 27
0
	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)
Esempio n. 28
0
 def generateCursor(self, element):
     cursorPixmap = QPixmap(32,32)
     hotX = element.getAttribute('__hotX')
     if hotX == None:
         hotX = element.width()/2
     hotY = element.getAttribute('__hotY')
     if hotY == None:
         hotY = element.height()/2
     cursorPixmap.fill(Qt.transparent)
     element.moveTo(0,0)
     painter = QPainter()
     painter.begin(cursorPixmap)
     id = element.getAttribute('id')
     assert id != None and isinstance(id,str)
     self.render(painter,"#" + id)
     painter.end()
     return QCursor(cursorPixmap,hotX,hotY)
Esempio n. 29
0
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        c = QColor()
        c.setNamedColor(self._window_bgcolor)

        h, s, l, a = c.getHsl()
        c.setHsl(h, s, 100, a)

        pen = QPen(c, 8, QtCore.Qt.SolidLine)
        qp.setPen(pen)

        qp.drawRoundedRect(event.rect(), 12, 12)
        qp.end()
Esempio n. 30
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()
Esempio n. 31
0
 def paintEvent(self, e):
     p = QPainter(self)
     style = QApplication.style()
     option = QStyleOptionButton()
     style.drawControl(QStyle.CE_PushButton, option, p)
     self._painted = True
Esempio n. 32
0
 def paintEvent(self, e):
     qp = QPainter()
     qp.begin(self)
     qp.setBrush(self.value)
     qp.drawRect(0, 5, self.width, self.height)
     qp.end()
    def paintEvent(self, event):
        mouse_pos = self.mapFromGlobal(QCursor.pos())
        is_hover = self.contentsRect().contains(mouse_pos)

        if not self.new_ui:
            QPushButton.paintEvent(self, event)

        painter = QPainter(self)
        if self.new_ui and self.isChecked():
            painter.setRenderHint(QPainter.Antialiasing)
            painter.setPen(QPen(Qt.NoPen))
            painter.setBrush(self.highlight)
            painter.drawRoundedRect(event.rect(), 2, 2)

        painter.drawPixmap(2, 2, self.icon)

        if is_hover:
            painter.setCompositionMode(QPainter.CompositionMode_Screen)
            painter.drawPixmap(2, 2, self.icon)
Esempio n. 34
0
 def testSetBrushGradient(self):
     painter = QPainter()
     gradient = QLinearGradient(0, 0, 0, 0)
     painter.setBrush(gradient)
Esempio n. 35
0
 def paintEvent(self, pe):
   painter = QPainter(self)
   pixmap = self._icons[0]
   pixmap = pixmap.scaled(self.size(), Qt.IgnoreAspectRatio)
   painter.drawPixmap(0, 0, pixmap)
Esempio n. 36
0
    def paintEvent(self, pe):
        if self.left_view and self.right_view and self.right_view.model():
            vr = self.left_view.visualRect(self.left_view.currentIndex())

            self.left_top = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr.topRight())).y()
            self.left_bottom = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr.bottomRight())).y()

            vr_top = self.right_view.visualRect(self.right_view.model().index(
                0, 0))
            vr = self.right_view.visualRect(self.right_view.model().index(
                self.right_view.model().rowCount() - 1, 0))

            self.right_top = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr_top.topLeft())).y()
            self.right_bottom = self.mapFromGlobal(
                self.left_view.viewport().mapToGlobal(vr.bottomLeft())).y()

            w = self.minimumWidth() - 1

            p = QPainter(self)
            p.setBrush(QBrush(QColor(210, 255, 210)))

            pen = QPen()
            pen.setColor(Qt.transparent)
            p.setPen(pen)

            poly = QPolygon()
            poly.append(QPoint(0, self.left_top))
            poly.append(QPoint(w, self.right_top))
            poly.append(QPoint(w, self.right_bottom))
            poly.append(QPoint(0, self.left_bottom))
            p.drawConvexPolygon(poly)

            p.setRenderHint(QPainter.Antialiasing)
            pen.setColor(Qt.GlobalColor.black)
            pen.setWidth(2)
            p.setPen(pen)
            p.drawLine(0, self.left_top, w, self.right_top)
            p.drawLine(0, self.left_bottom, w, self.right_bottom)
Esempio n. 37
0
    def paintEvent(self, pe):

        if self._drop_zones_shown:
            painter = QPainter(self.viewport(
            ))  # See documentation to know why I draw on the viewport
            painter.setFont(self._titles_font)
            vr = self.rect()

            nb_drop_zones = len(self._drop_zones_titles)

            subr = QRect(vr)
            subr.setHeight(vr.height() / nb_drop_zones)

            for i in range(nb_drop_zones):
                c = self._drop_zones_colors[i]

                text_pen = QPen()
                text_pen.setColor(inverse_colors(c))
                painter.setPen(text_pen)

                if i == self._selected_drop_zone:
                    # mainlog.debug("selected drop zone is {}".format(i))
                    c = c.lighter(200)
                painter.setBrush(c)

                subr.moveTop(int(i * vr.height() / nb_drop_zones))
                painter.drawRect(subr)
                painter.drawText(
                    QPoint(10, int((i + 0.5) * vr.height() / nb_drop_zones)),
                    self._drop_zones_titles[i])
            return None
        else:
            return super(AnimatedTableView, self).paintEvent(pe)
Esempio n. 38
0
    def paintEvent(self, event):
        # print self.height()

        s = (self.target_angle - self.angle) * 0.09

        self.angle += s
        if math.fabs(self.angle - self.target_angle) < 0.001:
            self.angle = self.target_angle
            self.timer.stop()

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

        qp = QPainterPath()

        width = min(self.height(), (self.width() / 2))
        height = self.height()

        # center
        x = self.width() / 2

        big_radius = 1000
        y = big_radius + 10
        small_radius = big_radius - 15

        ac = math.atan(float(self.width()) / 2.0 /
                       float(big_radius)) / math.pi * 180.0 * 0.95

        qp.arcMoveTo(x - big_radius, y - big_radius, 2 * big_radius,
                     2 * big_radius, 90 - ac)
        qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius,
                 2 * big_radius, 90 - ac, 2 * ac)
        qp.arcTo(x - small_radius, y - small_radius, 2 * small_radius,
                 2 * small_radius, 90 + ac, -2 * ac)
        qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius,
                 2 * big_radius, 90 - ac, 0)
        # qp.lineTo(x+big_radius,y)

        grange = ac * 2.0 / 360.0

        # Centered on 0, starting at angle 90-ac, counterclockwise
        self.gradient = QConicalGradient(0, 0, 90 - ac - 1)

        if self.gradient_type == 1:
            self.gradient.setColorAt(0, Qt.GlobalColor.red)
            self.gradient.setColorAt(0.1, Qt.GlobalColor.yellow)
            self.gradient.setColorAt(0.2, Qt.GlobalColor.green)
            self.gradient.setColorAt(0.5, Qt.GlobalColor.green)
            self.gradient.setColorAt(0.5, Qt.GlobalColor.green)
        elif self.gradient_type == 2:
            self.gradient.setColorAt(0, Qt.GlobalColor.green)
            self.gradient.setColorAt(0.6 * grange, Qt.GlobalColor.yellow)
            self.gradient.setColorAt(1 * grange, Qt.GlobalColor.red)
        elif self.gradient_type == 3:
            self.gradient.setColorAt(0 * grange, Qt.GlobalColor.red)
            self.gradient.setColorAt(0.05 * grange, Qt.GlobalColor.yellow)
            self.gradient.setColorAt(0.1 * grange, Qt.GlobalColor.green)
            self.gradient.setColorAt(0.4 * grange, Qt.GlobalColor.green)
            self.gradient.setColorAt(0.45 * grange, Qt.GlobalColor.yellow)
            self.gradient.setColorAt(0.5 * grange, Qt.GlobalColor.red)

        self.gradient.setCenter(x, y)
        painter.fillPath(qp, QBrush(self.gradient))

        pen = QPen()
        pen.setColor(Qt.GlobalColor.black)
        pen.setWidth(max(1, int(1 * self.width() / 300)))
        painter.setPen(pen)
        painter.drawPath(qp)

        qp = QPainterPath()
        #qp.moveTo(0,0)
        #qp.lineTo(x,y)
        #qp.lineTo(self.width(),0)

        angle = 0
        ac = math.atan(float(self.width()) / 2.0 / float(big_radius)) * 0.95

        if self.direction == self.UNIDIRECTIONAL:
            angle = math.pi / 2 + ac * (1 - 2 * self.angle)

        elif self.direction == self.BIDIRECTIONAL:
            angle = math.pi / 2 - self.angle * ac

        length = big_radius + 10
        short_length = small_radius - 10

        qp.moveTo(x + math.cos(angle) * short_length,
                  y - math.sin(angle) * short_length)
        qp.lineTo(x + math.cos(angle) * length, y - math.sin(angle) * length)
        pen = QPen()
        pen.setCapStyle(Qt.RoundCap)
        pen.setColor(Qt.GlobalColor.black)
        pen.setWidth(max(3, int(3 * width / 300)))
        painter.setPen(pen)
        painter.drawPath(qp)

        qp = QPainterPath()
        delta = self.width() * 0.025

        # print "{}-{} {} c:{}".format(x,y,delta,math.cos(angle))
        qp.moveTo(x + delta + math.cos(angle) * short_length,
                  y + delta - math.sin(angle) * short_length)
        qp.lineTo(x + delta + math.cos(angle) * length,
                  y + delta - math.sin(angle) * length)
        pen = QPen()
        pen.setCapStyle(Qt.RoundCap)
        pen.setColor(QColor.fromRgbF(0, 0, 0, 0.3))
        pen.setWidth(max(3, int(3 * width / 300)))
        painter.setPen(pen)
        painter.drawPath(qp)

        qp = QPainterPath()
        qp.addRect(0, 0, self.width(), self.height())
        painter.drawPath(qp)
Esempio n. 39
0
class QPainterDrawText(unittest.TestCase):
    def setUp(self):
        self.painter = QPainter()
        self.text = 'teste!'

    def tearDown(self):
        del self.text
        del self.painter

    def testDrawText(self):
        # bug #254
        rect = self.painter.drawText(100, 100, 100, 100,
                                     Qt.AlignCenter | Qt.TextWordWrap,
                                     self.text)
        self.assert_(isinstance(rect, QRect))

    def testDrawTextWithRect(self):
        # bug #225
        rect = QRect(100, 100, 100, 100)
        newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
                                        self.text)

        self.assert_(isinstance(newRect, QRect))

    def testDrawTextWithRectF(self):
        '''QPainter.drawText(QRectF, ... ,QRectF*) inject code'''
        rect = QRectF(100, 52.3, 100, 100)
        newRect = self.painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
                                        self.text)

        self.assert_(isinstance(newRect, QRectF))

    def testDrawOverloads(self):
        '''Calls QPainter.drawLines overloads, if something is
           wrong Exception and chaos ensues. Bug #395'''
        self.painter.drawLines([QLine(QPoint(0, 0), QPoint(1, 1))])
        self.painter.drawLines([QPoint(0, 0), QPoint(1, 1)])
        self.painter.drawLines([QPointF(0, 0), QPointF(1, 1)])
        self.painter.drawLines([QLineF(QPointF(0, 0), QPointF(1, 1))])
        self.painter.drawPoints([QPoint(0, 0), QPoint(1, 1)])
        self.painter.drawPoints([QPointF(0, 0), QPointF(1, 1)])
        self.painter.drawConvexPolygon([
            QPointF(10.0, 80.0),
            QPointF(20.0, 10.0),
            QPointF(80.0, 30.0),
            QPointF(90.0, 70.0)
        ])
        self.painter.drawConvexPolygon([
            QPoint(10.0, 80.0),
            QPoint(20.0, 10.0),
            QPoint(80.0, 30.0),
            QPoint(90.0, 70.0)
        ])
        self.painter.drawPolygon([
            QPointF(10.0, 80.0),
            QPointF(20.0, 10.0),
            QPointF(80.0, 30.0),
            QPointF(90.0, 70.0)
        ])
        self.painter.drawPolygon([
            QPoint(10.0, 80.0),
            QPoint(20.0, 10.0),
            QPoint(80.0, 30.0),
            QPoint(90.0, 70.0)
        ])
        self.painter.drawPolyline([
            QPointF(10.0, 80.0),
            QPointF(20.0, 10.0),
            QPointF(80.0, 30.0),
            QPointF(90.0, 70.0)
        ])
        self.painter.drawPolyline([
            QPoint(10.0, 80.0),
            QPoint(20.0, 10.0),
            QPoint(80.0, 30.0),
            QPoint(90.0, 70.0)
        ])
Esempio n. 40
0
 def paintEvent(self, e):
     p = QPainter(self)
     p.drawPicture(0, 0, self._picture)
     self._app.quit()
Esempio n. 41
0
    def paintEvent(self, ev):
        if self.isEnabled():
            color = self.color
            colorBorder = [0.4, 0.4, 0.4]
        else:
            color = [0.8, 0.8, 0.8]
            colorBorder = [0.7, 0.7, 0.7]

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)

        if self.isChecked():
            pen = QPen(QColor.fromRgbF(0.2, 0.2, 0.2))
            pen.setWidth(2.0)
        else:
            pen = QPen(
                QColor.fromRgbF(colorBorder[0], colorBorder[1],
                                colorBorder[2]))
            pen.setWidth(1.0)

        size = self.size()
        sizeCircle = 12.0
        x = size.width() / 2.0 - (sizeCircle / 2.0)
        y = size.height() / 2.0 - (sizeCircle / 2.0)
        rect = QRectF(x, y, sizeCircle, sizeCircle)
        painter.setPen(pen)
        painter.setBrush(QColor.fromRgbF(color[0], color[1], color[2]))
        painter.drawEllipse(rect)
Esempio n. 42
0
 def setUp(self):
     self.painter = QPainter()
     self.text = 'teste!'
Esempio n. 43
0
    def createPixmap(self):
        """Creates the pixmap shown when this label is dragged."""
        font_metric = QFontMetrics(QFont())
        text_size = font_metric.size(Qt.TextSingleLine, self.text)
        image = QImage(text_size.width() + 4,
                       text_size.height() + 4,
                       QImage.Format_ARGB32_Premultiplied)
        image.fill(qRgba(240, 240, 120, 255))

        painter = QPainter()
        painter.begin(image)
        painter.setFont(QFont())
        painter.setBrush(Qt.black)
        painter.drawText(QRect(QPoint(2, 2), text_size), Qt.AlignCenter,
                         self.text)
        painter.end()
        return image
Esempio n. 44
0
def paint(paintdevice):
    painter = QPainter(paintdevice)
    yield painter
    painter.end()
Esempio n. 45
0
    def paint(self, painter, option, widget=None):
        """@reimp @public
    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
    """
        #Q_UNUSED(option)
        #Q_UNUSED(widget)
        d = self.__d
        key = d.hash
        pm = QPixmap()
        if not QPixmapCache.find(key, pm):
            # Set up a convenient path
            path = QPainterPath()
            path.setFillRule(Qt.OddEvenFill)
            path.addEllipse(QPointF(d.actualOuterRadius, d.actualOuterRadius),
                            d.actualOuterRadius, d.actualOuterRadius)
            path.addEllipse(QPointF(d.actualOuterRadius, d.actualOuterRadius),
                            d.actualInnerRadius, d.actualInnerRadius)

            nActualDiameter = 2.0 * d.actualOuterRadius
            pm = QPixmap(nActualDiameter, nActualDiameter)
            pm.fill(Qt.transparent)
            p = QPainter(pm)

            # Draw the ring background
            p.setPen(Qt.NoPen)
            p.setBrush(d.backgroundColor)
            p.setRenderHint(QPainter.Antialiasing)
            p.drawPath(path)

            # Draw the ring foreground
            # TODO: Expose this gradient as Qml Property
            gradient = QConicalGradient(d.actualOuterRadius,
                                        d.actualOuterRadius, 0.0)
            gradient.setColorAt(0.0, Qt.transparent)
            gradient.setColorAt(0.05, d.foregroundColor)
            gradient.setColorAt(0.8, Qt.transparent)

            p.setBrush(gradient)
            p.drawPath(path)
            p.end()

            QPixmapCache.insert(key, pm)

        # Draw pixmap at center of item
        w, h = self.width(), self.height()
        sz = min(w, h)
        painter.drawPixmap(0.5 * (w - sz), 0.5 * (h - sz), pm)
Esempio n. 46
0
 def set_image(self, image):
     self.dirty = True
     self.fill(0)
     painter = QPainter(self)
     painter.drawImage(0, 0, image)
Esempio n. 47
0
 def paintEvent(self, event):
     qp = QPainter()
     qp.begin(self)
     self.drawing(qp)
Esempio n. 48
0
 def paintEvent(self, e):
     qp = QPainter()
     qp.begin(self)
     qp.setBrush(QColor(*self.value))
     qp.drawRect(0, 0, self.bar_width, 20)
     qp.end()
Esempio n. 49
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)
Esempio n. 50
0
    def saveAsPdf(self, fn, force=False):
        """
        Save bar image as a eps file.

        Args:
            fn: Filename
            force: if True, overwrites an existing file. If false, raises a
            RuntimeError if file already exists.
        """
        printer = QPrinter(QPrinter.HighResolution)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOutputFileName(fn)
        printer.setFullPage(True)
        printer.setPageSize(QPrinter.Custom)
        printer.setPaperSize(QSizeF(*self.size), QPrinter.Millimeter)
        printer.setPageMargins(0, 0, 0, 0, QPrinter.Millimeter)

        painter = QPainter(printer)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(Qt.white)
        painter.setPen(Qt.white)
        painter.drawRect(QRect(0, 0, *self.size))

        targetrect = QRectF(0, 0, printer.width(), printer.height())
        sourcerect = QRectF(0, 0, *self.size)
        self.render(painter, targetrect, sourcerect)
        painter.end()
        return True
Esempio n. 51
0
	def paintEvent(self, ev):
		size = self.size()
		height = size.height()-5
		width = size.width()-5

		offset = 0.5
		rect = QRectF(2.0+offset, 2.0+offset, width, height)
		painter = QPainter(self)

		painter.setPen(self._pen)
		painter.setBrush(QColor(self._color[0], self._color[1], self._color[2]))
		painter.setRenderHint(QPainter.Antialiasing)
		painter.setRenderHint(QPainter.HighQualityAntialiasing)
		painter.drawRoundedRect(rect, 4, 4)
Esempio n. 52
0
    def paintEvent(self, event):
        painter = QPainter(self)

        width = self.width()
        height = self.height()

        pen = QPen()
        pen.setBrush(Qt.black)

        pen.setWidth(2)
        painter.setPen(pen)
        painter.setRenderHint(painter.Antialiasing)
        painter.drawEllipse(0, 0, width, height)

        painter.drawLine(width - 20, height // 2, width - 1, height // 2)
        painter.drawLine(0, height // 2, 20, height // 2)
        painter.drawLine(width // 2, 0, width // 2, 20)
        painter.drawLine(width // 2, height - 20, width // 2, height - 1)

        painter.drawText(0, 20, width, height - 20,
                         Qt.AlignHCenter | Qt.AlignTop, "N")
        painter.drawText(0, 0, width, height - 20,
                         Qt.AlignHCenter | Qt.AlignBottom, "S")
        painter.drawText(25, 0, width - 25, height,
                         Qt.AlignVCenter | Qt.AlignLeft, "W")
        painter.drawText(0, 0, width - 25, height,
                         Qt.AlignVCenter | Qt.AlignRight, "E")

        pen.setWidth(4)
        pen.setBrush(Qt.blue)
        painter.setPen(pen)

        x = (math.cos(-self.heading) * width // 2) + width // 2
        y = (math.sin(-self.heading) * height // 2) + height // 2

        painter.drawLine(width // 2, height // 2, x, y)
Esempio n. 53
0
    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()
Esempio n. 54
0
    def saveAsBitmap(self, fn):
        """
        Save bar image as a jpg file. Overwrites a file already existing in
        filesystem.

        https://stackoverflow.com/questions/7451183/how-to-create-image-file\
        -from-qgraphicsscene-qgraphicsview#11642517

        Args:
            fn: Filename
        Returns:
            True on success
        """
        size = self.size
        pixelsx = max(1200, size[0])
        pixelsy = int(pixelsx*size[1]/size[0])
        imagesize = (pixelsx, pixelsy)
        image = QImage(pixelsx,
                       pixelsy,
                       QImage.Format_ARGB32_Premultiplied)

        painter = QPainter(image)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(Qt.white)
        painter.setPen(Qt.white)
        painter.drawRect(QRect(0, 0, *imagesize))

        targetrect = QRectF(0, 0, *imagesize)
        sourcerect = QRectF(0, 0, *size)
        self.render(painter, targetrect, sourcerect)
        painter.end()

        return image.save(fn)
Esempio n. 55
0
 def paintEvent(self, event):
     '''
 Method to run on paint events
 '''
     painter = QPainter()
     # Get a QPainter object
     painter.begin(self)
     # Begin painting
     painter.setRenderHint(QPainter.Antialiasing)
     # Set a rendering option
     painter.setBrush(Qt.transparent)
     # Set the paint brush to transparent
     painter.drawRect(0, 0, 20, 20)
     # Draw a rectangle with width = height = 20
     painter.setBrush(Qt.green)
     # Set the paint brush color to green
     painter.drawEllipse(QPoint(10, 10), 9, 9)
     # Draw a circle that fills most of the rectangle
     painter.end()
Esempio n. 56
0
 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)
Esempio n. 57
0
 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)
Esempio n. 58
0
class GrWidget(QWidget):
    def __init__(self):
        super(GrWidget, self).__init__()

        self.setup_ui(self)

        os.environ["GKS_WSTYPE"] = "381"
        os.environ["GKS_DOUBLE_BUF"] = "True"

        self.w = 500
        self.h = 500
        self.beginx = self.x = 0
        self.beginy = self.y = 0
        self.painter = QPainter()
        self.isolevel = (data.min() + data.max()) // 2
        self.export = False
        self.needs_refresh = True

    @staticmethod
    def setup_ui(form):
        form.setWindowTitle("GrWidget")
        form.resize(QtCore.QSize(500, 500).expandedTo(form.minimumSizeHint()))

    def draw_image(self):
        if not self.needs_refresh:
            return
        self.needs_refresh = False
        gr.clearws()
        gr.setwindow(0, self.w, 0, self.h)
        gr.setviewport(0, 1, 0, 1)

        gr3.setbackgroundcolor(1, 1, 1, 0)
        vertices, normals = gr3.triangulate(data,
                                            (1.0 / 64, 1.0 / 64, 1.0 / 128),
                                            (-0.5, -0.5, -0.5), self.isolevel)
        mesh = gr3.createmesh(
            len(vertices) * 3, vertices, normals, np.ones(vertices.shape))
        gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 1, 1),
                     (1, 1, 1))
        center = spherical_to_cartesian(-2,
                                        np.pi * self.y / self.h + np.pi / 2,
                                        np.pi * self.x / self.w)
        up = spherical_to_cartesian(1, np.pi * self.y / self.h + np.pi,
                                    np.pi * self.x / self.w)
        gr3.cameralookat(center[0], center[1], -0.25 + center[2], 0, 0, -0.25,
                         up[0], up[1], up[2])
        gr3.drawimage(0, self.w, 0, self.h, self.w, self.h,
                      gr3.GR3_Drawable.GR3_DRAWABLE_GKS)
        if self.export:
            gr3.export("mri.html", 800, 800)
            print("Saved current isosurface to mri.html")
            self.export = False
        gr3.clear()
        gr3.deletemesh(c_int(mesh.value))

    def mouseMoveEvent(self, event):
        self.x += event.pos().x() - self.beginx
        self.y -= event.pos().y() - self.beginy
        self.beginx = event.pos().x()
        self.beginy = event.pos().y()
        self.needs_refresh = True
        self.update()

    def mousePressEvent(self, event):
        self.beginx = event.pos().x()
        self.beginy = event.pos().y()

    def keyPressEvent(self, event):
        if event.key() == QtCore.Qt.Key_Escape:
            self.close()
        elif event.text() == 'h':
            self.export = True
        self.needs_refresh = True
        self.update()

    def wheelEvent(self, ev):
        if hasattr(ev, 'delta'):
            delta = ev.delta()
        else:
            delta = ev.angleDelta().y()
        if delta > 0:
            if self.isolevel * 1.01 < data.max():
                self.isolevel *= 1.01
        else:
            if self.isolevel * 0.99 > data.min():
                self.isolevel *= 0.99
        self.isolevel = int(self.isolevel + 0.5)
        self.needs_refresh = True
        self.update()

    def resizeEvent(self, event):
        self.needs_refresh = True
        self.update()

    def paintEvent(self, ev):
        self.painter.begin(self)
        if have_pyside:
            os.environ['GKSconid'] = "%x!%x" % (
                int(shiboken.getCppPointer(self)[0]),
                int(shiboken.getCppPointer(self.painter)[0]))
        else:
            os.environ["GKSconid"] = "%x!%x" % (unwrapinstance(self),
                                                unwrapinstance(self.painter))
        self.draw_image()
        gr.updatews()
        self.painter.end()
Esempio n. 59
0
 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()
Esempio n. 60
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)

        colour = self._colour
        if not self._lit:
            colour = self._colour.darker(300)
        painter.setPen(QPen(Qt.black, 1))
        painter.setBrush(QBrush(colour))

        rect = event.rect()
        radius = min(rect.width(), rect.height()) / 3
        painter.drawEllipse(rect.center(), radius, radius)

        painter.end()