Python PyQt4.QtGui 模块,QPainter() 实例源码

我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用PyQt4.QtGui.QPainter()

项目:quartz-browser    作者:ksharindam    | 项目源码 | 文件源码
def saveAsImage(self):
        """ Saves the whole page as PNG/JPG image"""
        title = self.tabWidget.currentWidget().page().mainFrame().title()
        title == validateFileName(title)
        filename = QFileDialog.getSaveFileName(self,
                                      "Select Image to Save", downloaddir + title +".jpg",
                                      "JPEG Image (*.jpg);;PNG Image (*.png)" )
        if not filename.isEmpty():
            viewportsize = self.tabWidget.currentWidget().page().viewportSize()
            contentsize = self.tabWidget.currentWidget().page().mainFrame().contentsSize()
            self.tabWidget.currentWidget().page().setViewportSize(contentsize)
            img = QPixmap(contentsize)
            painter = QPainter(img)
            self.tabWidget.currentWidget().page().mainFrame().render(painter, 0xff)# 0xff=QWebFrame.AllLayers
            painter.end()
            if img.save(filename):
                QMessageBox.information(self, "Successful !","Page has been successfully saved as\n"+filename)
            self.tabWidget.currentWidget().page().setViewportSize(viewportsize)
项目:quartz-browser    作者:ksharindam    | 项目源码 | 文件源码
def addToFavourites(self):
        dialog = QDialog(self)
        addbmkdialog = Add_Bookmark_Dialog()
        addbmkdialog.setupUi(dialog)
        dialog.setWindowTitle('Add to HomePage')
        addbmkdialog.titleEdit.setMaxLength(31)
        addbmkdialog.titleEdit.setText(self.tabWidget.currentWidget().page().mainFrame().title())
        addbmkdialog.addressEdit.setText(self.line.text())
        if (dialog.exec_() == QDialog.Accepted):
            title = unicode(addbmkdialog.titleEdit.text())
            addr = unicode(addbmkdialog.addressEdit.text())
            imgfile = str(time()) + '.jpg'
            viewportsize = self.tabWidget.currentWidget().page().viewportSize()
            contentsize = QSize(640, 640)
            self.tabWidget.currentWidget().page().setViewportSize(contentsize)
            img = QPixmap(contentsize)
            painter = QPainter(img)
            self.tabWidget.currentWidget().page().mainFrame().render(painter, 0xff)# 0xff=QWebFrame.AllLayers
            painter.end()
            self.tabWidget.currentWidget().page().setViewportSize(viewportsize)
            icon = img.scaledToWidth(184, 1).copy(0,0, 180, 120)
            icon.save(thumbnails_dir + imgfile)
            self.favourites = importFavourites(configdir + 'favourites.txt')
            self.favourites.append([title, addr, imgfile])
            exportFavourites(configdir + 'favourites.txt', self.favourites)
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def createIcon(self, nodeType):
        '''Create Icons for `libraryModel`.

        :param nodeType: Type of icon to create.
        '''
        pixmap = QtGui.QPixmap(60, 60)
        pixmap.fill()
        painter = QtGui.QPainter(pixmap)
        if nodeType == "transition":
            painter.setBrush(QtCore.Qt.white)
            painter.drawRect(5, 10, 50, 30)
        elif nodeType == "place":           
            painter.setBrush(QtCore.Qt.white)
            painter.drawEllipse(5, 10, 50, 30) 
        elif nodeType == "token":           
            painter.setBrush(QtCore.Qt.green)
            painter.drawEllipse(15, 15, 30, 30) 

        painter.end()
        return QtGui.QStandardItem( QtGui.QIcon(pixmap), nodeType[0].upper() + nodeType[1:] )
    #------------------------------------------------------------------------------------------------
项目:linkchecker-gui    作者:linkcheck    | 项目源码 | 文件源码
def lineNumberAreaPaintEvent (self, event):
        """Paint line numbers."""
        painter = QtGui.QPainter(self.lineNumberArea)
        painter.fillRect(event.rect(), QtCore.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.isVisible() 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.AlignRight, number)
            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            blockNumber += 1
项目:base_function    作者:Rockyzsu    | 项目源码 | 文件源码
def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        rect = self.contentsRect()
        boardTop = rect.bottom() - Board.BoardHeight * self.squareHeight()
        for i in range(Board.BoardHeight):
            for j in range(Board.BoardWidth):
                shape = self.shapeAt(j, Board.BoardHeight - i - 1)
                if shape != Tetrominoes.NoShape:
                    self.drawSquare(painter,
                                    rect.left() + j * self.squareWidth(),
                                    boardTop + i * self.squareHeight(), shape)
        if self.curPiece.shape() != Tetrominoes.NoShape:
            for i in range(4):
                x = self.curX + self.curPiece.x(i)
                y = self.curY - self.curPiece.y(i)
                self.drawSquare(painter, rect.left() + x * self.squareWidth(),
                                boardTop + (Board.BoardHeight - y - 1) * self.squareHeight(),
                                self.curPiece.shape())
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def save_View(self):
        outputimg = QtGui.QPixmap(self.view.width(), self.view.height())
        painter = QtGui.QPainter(outputimg)
        targetrect = QtCore.QRectF(0, 0, self.view.width(), self.view.height())
        sourcerect = QtCore.QRect(0, 0, self.view.width(), self.view.height())
        self.view.render(painter, targetrect, sourcerect)
        fname = self.new_scenario[:self.new_scenario.rfind('.')] + '.png'
        fname = QtGui.QFileDialog.getSaveFileName(self, 'Save image file',
                self.scenarios + fname, 'Image Files (*.png *.jpg *.bmp)')
        if fname != '':
            fname = str(fname)
            i = fname.rfind('.')
            if i < 0:
                fname = fname + '.png'
                i = fname.rfind('.')
            outputimg.save(fname, fname[i + 1:])
            try:
                comment = 'View saved to ' + fname[fname.rfind('/') + 1:]
            except:
                comment = 'View saved to ' + fname
            self.view.emit(QtCore.SIGNAL('statusmsg'), comment)
        painter.end()
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def __init__(self):
        QtGui.QGraphicsScene.__init__(self)
        self.exitLoop = False
        self.loopMax = 0
        self.get_config()
        self._gridGroup = None
        self._mgridGroup = None
        self.setBackgroundBrush(QtGui.QColor(self.colors['background']))
        if os.path.exists(self.map_file):
            war = QtGui.QImageReader(self.map_file)
            wa = war.read()
            pixMap = QtGui.QPixmap.fromImage(wa)
        else:
            ratio = abs(self.map_upper_left[1] - self.map_lower_right[1]) / \
                     abs(self.map_upper_left[0] - self.map_lower_right[0])
            pixMap = QtGui.QPixmap(200 * ratio, 200)
            if self.map != '':
                painter = QtGui.QPainter(pixMap)
                brush = QtGui.QBrush(QtGui.QColor('white'))
                painter.fillRect(QtCore.QRectF(0, 0, 200 * ratio, 200), brush)
                painter.setPen(QtGui.QColor('lightgray'))
                painter.drawText(QtCore.QRectF(0, 0, 200 * ratio, 200), QtCore.Qt.AlignCenter,
                                 'Map not found.')
                painter.end()
        self.addPixmap(pixMap)
        w = self.width()
        h = self.height()
        if isinstance(self.line_width, float):
            if self.line_width < 1:
                self.line_width = w * self.line_width
        self.upper_left = [0, 0, self.map_upper_left[1], self.map_upper_left[0]]
        self.lower_right = [w, h, self.map_lower_right[1], self.map_lower_right[0]]
        self.setSceneRect(-w * 0.05, -h * 0.05, w * 1.1, h * 1.1)
        self._positions = {}
        self._setupCoordTransform()
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def save_View(self):
        outputimg = QtGui.QPixmap(self.view.width(), self.view.height())
        painter = QtGui.QPainter(outputimg)
        targetrect = QtCore.QRectF(0, 0, self.view.width(), self.view.height())
        sourcerect = QtCore.QRect(0, 0, self.view.width(), self.view.height())
        self.view.render(painter, targetrect, sourcerect)
        fname = 'worldwindow_view.png'
        fname = QtGui.QFileDialog.getSaveFileName(self, 'Save image file',
                fname, 'Image Files (*.png *.jpg *.bmp)')
        if fname != '':
            fname = str(fname)
            i = fname.rfind('.')
            if i < 0:
                fname = fname + '.png'
                i = fname.rfind('.')
            outputimg.save(fname, fname[i + 1:])
            try:
                comment = 'View saved to ' + fname[fname.rfind('/') + 1:]
            except:
                comment = 'View saved to ' + fname
            self.view.emit(QtCore.SIGNAL('statusmsg'), comment)
        painter.end()
项目:rec-attend-public    作者:renmengye    | 项目源码 | 文件源码
def getHighlightedObject(self, qp):
        # This variable we want to fill
        self.highlightObj = None

        # Without labels we cannot do so
        if not self.annotation:
            return

        # If available its the selected object
        highlightObjId = -1
        # If not available but the polygon is empty or closed, its the mouse object
        if highlightObjId < 0 and not self.mouseOutsideImage:
            highlightObjId = self.mouseObj
        # Get the actual object that is highlighted
        if highlightObjId >= 0:
            self.highlightObj = self.annotation.objects[highlightObjId]
            self.highlightObjLabel = self.annotation.objects[highlightObjId].label

    # Draw the image in the given QPainter qp
项目:rec-attend-public    作者:renmengye    | 项目源码 | 文件源码
def drawDisp( self , qp ):
        if not self.dispOverlay:
            return 

        # Save QPainter settings to stack
        qp.save()
        # Define transparency
        qp.setOpacity(self.transp)
        # Draw the overlay image
        qp.drawImage(QtCore.QRect( self.xoff, self.yoff, self.w, self.h ),self.dispOverlay)
        # Restore settings
        qp.restore()

        return self.dispOverlay



    #############################
    ## Mouse/keyboard events
    #############################

    # Mouse moved
    # Need to save the mouse position
    # Need to drag a polygon point
    # Need to update the mouse selected object
项目:cityscapes-api    作者:renmengye    | 项目源码 | 文件源码
def getHighlightedObject(self, qp):
        # This variable we want to fill
        self.highlightObj = None

        # Without labels we cannot do so
        if not self.annotation:
            return

        # If available its the selected object
        highlightObjId = -1
        # If not available but the polygon is empty or closed, its the mouse object
        if highlightObjId < 0 and not self.mouseOutsideImage:
            highlightObjId = self.mouseObj
        # Get the actual object that is highlighted
        if highlightObjId >= 0:
            self.highlightObj = self.annotation.objects[highlightObjId]
            self.highlightObjLabel = self.annotation.objects[highlightObjId].label

    # Draw the image in the given QPainter qp
项目:cityscapes-api    作者:renmengye    | 项目源码 | 文件源码
def drawDisp( self , qp ):
        if not self.dispOverlay:
            return 

        # Save QPainter settings to stack
        qp.save()
        # Define transparency
        qp.setOpacity(self.transp)
        # Draw the overlay image
        qp.drawImage(QtCore.QRect( self.xoff, self.yoff, self.w, self.h ),self.dispOverlay)
        # Restore settings
        qp.restore()

        return self.dispOverlay



    #############################
    ## Mouse/keyboard events
    #############################

    # Mouse moved
    # Need to save the mouse position
    # Need to drag a polygon point
    # Need to update the mouse selected object
项目:pythoner    作者:jsRuner    | 项目源码 | 文件源码
def save_page(self,finished):
        #print finished
        if finished:
            print u"?????"
            size = self.webpage.mainFrame().contentsSize()
            print u"????%d?????%d" % (size.width(),size.height())
            self.webpage.setViewportSize(QtCore.QSize(size.width()+16,size.height()))
            img = QtGui.QImage(size, QtGui.QImage.Format_ARGB32)
            painter = QtGui.QPainter(img)
            self.webpage.mainFrame().render(painter)
            painter.end()
            filename= self.filename;
            if img.save(filename):
                filepath = os.path.join(os.path.dirname(__file__), filename)
                print u"?????%s" % filepath
            else:
                print u"????";
        else:
            print u"???????"
        self.close()
项目:pythoner    作者:jsRuner    | 项目源码 | 文件源码
def save_page(self,finished):
        #print finished
        if finished:
            print u"?????"
            size = self.webpage.mainFrame().contentsSize()
            print u"????%d?????%d" % (size.width(),size.height())
            self.webpage.setViewportSize(QtCore.QSize(size.width()+16,size.height()))
            img = QtGui.QImage(size, QtGui.QImage.Format_ARGB32)
            painter = QtGui.QPainter(img)
            self.webpage.mainFrame().render(painter)
            painter.end()
            filename= self.filename;
            if img.save(filename):
                filepath = os.path.join(os.path.dirname(__file__), filename)
                print u"?????%s" % filepath
            else:
                print u"????";
        else:
            print u"???????"
        self.close()
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
def getHighlightedObject(self, qp):
        # This variable we want to fill
        self.highlightObj = None

        # Without labels we cannot do so
        if not self.annotation:
            return

        # If available its the selected object
        highlightObjId = -1
        # If not available but the polygon is empty or closed, its the mouse object
        if highlightObjId < 0 and not self.mouseOutsideImage:
            highlightObjId = self.mouseObj
        # Get the actual object that is highlighted
        if highlightObjId >= 0:
            self.highlightObj = self.annotation.objects[highlightObjId]
            self.highlightObjLabel = self.annotation.objects[highlightObjId].label

    # Draw the image in the given QPainter qp
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
def drawDisp( self , qp ):
        if not self.dispOverlay:
            return 

        # Save QPainter settings to stack
        qp.save()
        # Define transparency
        qp.setOpacity(self.transp)
        # Draw the overlay image
        qp.drawImage(QtCore.QRect( self.xoff, self.yoff, self.w, self.h ),self.dispOverlay)
        # Restore settings
        qp.restore()

        return self.dispOverlay



    #############################
    ## Mouse/keyboard events
    #############################

    # Mouse moved
    # Need to save the mouse position
    # Need to drag a polygon point
    # Need to update the mouse selected object
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
def getHighlightedObject(self, qp):
        # These variables we want to fill
        self.highlightObjs = []
        self.highlightObjLabel = None

        # Without labels we cannot do so
        if not self.annotation:
            return

        # If available set the selected objects
        highlightObjIds = self.selObjs
        # If not available but the polygon is empty or closed, its the mouse object
        if not highlightObjIds and (self.drawPoly.isEmpty() or self.drawPolyClosed) and self.mouseObj>=0 and not self.mouseOutsideImage:
            highlightObjIds = [self.mouseObj]
        # Get the actual object that is highlighted
        if highlightObjIds:
            self.highlightObjs = [ self.annotation.objects[i] for i in highlightObjIds ]
        # Set the highlight object label if appropriate
        if self.config.highlight:
            self.highlightObjLabel = self.config.highlightLabelSelection
        elif len(highlightObjIds) == 1 and self.config.correctionMode:
            self.highlightObjLabel = self.annotation.objects[highlightObjIds[-1]].label

    # Draw the image in the given QPainter qp
项目:pyDashboard    作者:jtsmith2    | 项目源码 | 文件源码
def basefinished(self):
        if self.basereply.error() != QNetworkReply.NoError: return
        self.basepixmap = QPixmap()
        self.basepixmap.loadFromData(self.basereply.readAll())
        if self.basepixmap.size() != self.rect.size():
            self.basepixmap = self.basepixmap.scaled(self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
        if self.satellite:
            p = QPixmap(self.basepixmap.size())
            p.fill(Qt.transparent)
            painter = QPainter()
            painter.begin(p)
            painter.setOpacity(0.6)
            painter.drawPixmap(0,0,self.basepixmap)
            painter.end()
            self.basepixmap = p
            self.wwx.setPixmap(self.basepixmap)
        else:
            self.setPixmap(self.basepixmap)
项目:picasso    作者:jungmannlab    | 项目源码 | 文件源码
def draw_scalebar(self, image):
        if self.window.display_settings_dialog.scalebar_groupbox.isChecked():
            pixelsize = self.window.display_settings_dialog.pixelsize.value()
            scalebar = self.window.display_settings_dialog.scalebar.value()
            length_camerapxl = scalebar / pixelsize
            length_displaypxl = int(round(self.width() * length_camerapxl / self.viewport_width()))
            height = max(int(round(0.15 * length_displaypxl)), 1)
            painter = QtGui.QPainter(image)
            painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
            painter.setBrush(QtGui.QBrush(QtGui.QColor('white')))
            x = self.width() - length_displaypxl - 35
            y = self.height() - height - 20
            painter.drawRect(x, y, length_displaypxl + 0, height + 0)
            if self.window.display_settings_dialog.scalebar_text.isChecked():
                font = painter.font()
                font.setPixelSize(20)
                painter.setFont(font)
                painter.setPen(QtGui.QColor('white'))
                text_spacer = 40
                text_width = length_displaypxl +2*text_spacer
                text_height = text_spacer
                painter.drawText(x-text_spacer, y-25, text_width, text_height, QtCore.Qt.AlignHCenter,str(scalebar)+' nm')
        return image
项目:picasso    作者:jungmannlab    | 项目源码 | 文件源码
def draw_minimap(self, image):
        if self.window.display_settings_dialog.minimap.isChecked():
            movie_height, movie_width = self.movie_size()
            length_minimap = 100
            height_minimap = movie_height/movie_width*100
            #draw in the upper right corner, overview rectangle
            x = self.width() - length_minimap - 20
            y = 20
            painter = QtGui.QPainter(image)
            painter.setPen(QtGui.QColor('white'))
            painter.drawRect(x, y, length_minimap + 0, height_minimap + 0)
            painter.setPen(QtGui.QColor('yellow'))
            length = self.viewport_width()/movie_width*length_minimap
            height = self.viewport_height()/movie_height*height_minimap
            x_vp = self.viewport[0][1]/movie_width*length_minimap
            y_vp = self.viewport[0][0]/movie_height*length_minimap
            painter.drawRect(x+x_vp, y+y_vp, length + 0, height + 0)
        return image
项目:picasso    作者:jungmannlab    | 项目源码 | 文件源码
def update_cursor(self):
        if self._mode == 'Zoom':
            self.unsetCursor()
        elif self._mode == 'Pick':
            diameter = self.window.tools_settings_dialog.pick_diameter.value()
            diameter = self.width() * diameter / self.viewport_width()
            pixmap_size = ceil(diameter)
            pixmap = QtGui.QPixmap(pixmap_size, pixmap_size)
            pixmap.fill(QtCore.Qt.transparent)
            painter = QtGui.QPainter(pixmap)
            painter.setPen(QtGui.QColor('white'))
            offset = (pixmap_size - diameter) / 2
            painter.drawEllipse(offset, offset, diameter, diameter)
            painter.end()
            cursor = QtGui.QCursor(pixmap)
            self.setCursor(cursor)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def __init__(self):
        pixmap = QtGui.QPixmap(32, 32)
        pixmap.fill(QtCore.Qt.transparent)
        qp = QtGui.QPainter(pixmap)
        qp.setRenderHints(QtGui.QPainter.Antialiasing)
        qp.translate(.5, .5)
        qp.setPen(self.limit_pen)
        qp.drawLine(0, 8, 15, 8)
        qp.setPen(self.arrow_pen)
        qp.setBrush(self.brush)
        path = QtGui.QPainterPath()
        path.moveTo(3, 1)
        path.lineTo(12, 1)
        path.lineTo(7.5, 7)
        path.closeSubpath()
        qp.drawPath(path)
        del qp
        DirCursorClass.__init__(self, pixmap, 8, 8)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def __init__(self):
        pixmap = QtGui.QPixmap(32, 32)
        pixmap.fill(QtCore.Qt.transparent)
        qp = QtGui.QPainter(pixmap)
        qp.setRenderHints(QtGui.QPainter.Antialiasing)
        qp.translate(.5, .5)
        qp.setPen(self.limit_pen)
        qp.drawLine(1, 0, 1, 15)
        qp.setPen(self.arrow_pen)
        qp.setBrush(self.brush)
        path = QtGui.QPainterPath()
        path.moveTo(1, 7.5)
        path.lineTo(8, 12)
        path.lineTo(8, 3)
        path.closeSubpath()
        qp.drawPath(path)
        del qp
        DirCursorClass.__init__(self, pixmap, 1, 8)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def __init__(self):
        pixmap = QtGui.QPixmap(32, 32)
        pixmap.fill(QtCore.Qt.transparent)
        qp = QtGui.QPainter(pixmap)
        qp.setRenderHints(QtGui.QPainter.Antialiasing)
        qp.translate(.5, .5)
        qp.setPen(self.limit_pen)
        qp.drawLine(8, 0, 8, 15)
        qp.setPen(self.arrow_pen)
        qp.setBrush(self.brush)
        path = QtGui.QPainterPath()
        path.moveTo(1, 3)
        path.lineTo(1, 12)
        path.lineTo(7, 7.5)
        path.closeSubpath()
        qp.drawPath(path)
        del qp
        DirCursorClass.__init__(self, pixmap, 8, 8)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def paintEvent(self, event):
        qp = QtGui.QPainter()
        qp.begin(self)
        qp.setRenderHints(QtGui.QPainter.Antialiasing)
        qp.translate(self.base_translate)
        qp.setPen(self.pen)
#        qp.drawRect(0, 0, self.width()-1, self.height()-1)

        qp.setFont(self.font)
        qp.drawText(self.label_rect, self.text_align, self.text)
        if self.path:
            qp.setBrush(self.brush)
            qp.translate(self.path_rect.x(), self.path_rect.y())
            qp.drawPath(self.path)

        qp.end()
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def __init__(self, parent, width, height=None):
        QtGui.QWidget.__init__(self, parent)
        self.setMinimumSize(2, 2)
        if width < self.minimumWidth():
            width = self.minimumWidth()
        if height is None:
            height = width
        else:
            if height < self.minimumHeight():
                height = self.minimumHeight()
        self.setFixedSize(width, height)

#    def paintEvent(self, e):
#        qp = QtGui.QPainter()
#        qp.begin(self)
#        qp.setBrush(QtCore.Qt.white)
#        qp.drawRect(0, 0, self.width(), self.height())
#        qp.end()
#
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def resizeEvent(self, event):
        QtGui.QWidget.resizeEvent(self, event)
        if not self.reference: return
        object_rect = self.reference.mapToScene(self.reference.rect())
        real_rect = self.main.display.mapFromScene(object_rect).boundingRect()
        real_pos = self.mapFromGlobal(self.main.display.mapToGlobal(real_rect.topLeft()))
        mask_rect = QtCore.QRect(real_pos, real_rect.size())
        mask_rect.adjust(-3, -3, -8, -3)
        bmp = QtGui.QBitmap(self.width(), self.height())
        bmp.clear()
        qp = QtGui.QPainter(bmp)
        qp.setPen(QtCore.Qt.black)
        qp.setBrush(QtCore.Qt.black)
        qp.drawRect(0, 0, self.width(), self.height())
        qp.eraseRect(mask_rect)
        qp.end()
        self.setMask(bmp)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def createDragData(self):
        self.drag = QtGui.QDrag(self)
        data = QtCore.QMimeData()
        wave_len = self.selection[1] + 1 - self.selection[0]
        samples = self.current_data[self.selection[0] * 256 + self.offset:(self.selection[1] + 1) * 256 + self.offset]
        data.setData('audio/wavesamples', samples)
        data.setText(self.current_source)
        path = QtGui.QPainterPath()
        sampwidth_int = self.current_sampwidth_int / 2
        path.moveTo(0, sampwidth_int - audioop.getsample(samples, self.current_sampwidth, 0))
        for s in xrange(1, len(samples)/2):
            path.lineTo(s, sampwidth_int - audioop.getsample(samples, self.current_sampwidth, s))
        wave_size = self.main.wavetable_view.width() / 64
        pixmap = QtGui.QPixmap(wave_size * wave_len, 48)
        pixmap.fill(QtCore.Qt.transparent)
        qp = QtGui.QPainter(pixmap)
        qp.setRenderHints(qp.Antialiasing)
        qp.scale((wave_size * wave_len / path.boundingRect().width()), 48. / self.current_sampwidth_int)
        qp.drawPath(path)
        qp.end()
        self.drag.setPixmap(pixmap)
        self.drag.setMimeData(data)
        self.drag.exec_()
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def createDragData(self):
        if not self.selection: return
        start = self.selection[0]
        end = self.selection[-1]
        if start == end:
            self.waveobj_list[start].preview_rect.setSelected(True)
        self.drag = QtGui.QDrag(self)
        data = MimeData()
        data.setData('audio/waves', QtCore.QByteArray('{}:{}'.format(start, end)))
        data.setReferenceData(self.main)
        pixmap = QtGui.QPixmap(int(self.viewport().rect().width() / 64. * (end - start + 1)), self.height())
        pixmap.fill(QtGui.QColor(192, 192, 192, 128))
        qp = QtGui.QPainter(pixmap)
        qp.setRenderHints(qp.Antialiasing)
        x = self.mapFromScene(self.waveobj_list[start].preview_rect.pos()).x()
        width = self.mapFromScene(self.waveobj_list[end].preview_rect.pos()).x() + self.mapFromScene(self.waveobj_list[end].preview_rect.boundingRect().topRight()).x() - x
        self.render(qp, source=QtCore.QRect(x, self.wavegroup.boundingRect().y(), width, self.mapToScene(self.viewport().rect()).boundingRect().height()), mode=QtCore.Qt.IgnoreAspectRatio)
        qp.end()
        self.drag.setPixmap(pixmap)
        self.drag.setMimeData(data)
        self.drag.exec_()
项目:Semi-automatic-Annotation    作者:Luoyadan    | 项目源码 | 文件源码
def _draw_dots(self, points, color):
        # draw_dots using qt canvas
        r, g, b, o = color      

        if self.img_arr is None:
            self.img_arr = self.ref_pic.img_arr
        qImg = cvtrgb2qtimage(self.img_arr)
        image = QtGui.QPixmap(qImg)

        radx = 2
        rady = 2
        draw = QtGui.QPainter()
        draw.begin(image)
        draw.setBrush(QtGui.QColor(r, g, b, o))
        for p in points:
            center = QtCore.QPoint(p[1], p[0])
            draw.drawEllipse(center, radx, rady)
        draw.end()
        self.setPixmap(image)
项目:Semi-automatic-Annotation    作者:Luoyadan    | 项目源码 | 文件源码
def _draw_dots(self, points, color):
        # draw_dots using qt canvas
        r, g, b, o = color      

        if self.img_arr is None:
            self.img_arr = self.ref_pic.img_arr
        qImg = cvtrgb2qtimage(self.img_arr)
        image = QtGui.QPixmap(qImg)

        radx = 2
        rady = 2
        draw = QtGui.QPainter()
        draw.begin(image)
        draw.setBrush(QtGui.QColor(r, g, b, o))
        for p in points:
            center = QtCore.QPoint(p[1], p[0])
            draw.drawEllipse(center, radx, rady)
        draw.end()
        self.setPixmap(image)
项目:AnimeWatch    作者:kanishka-linux    | 项目源码 | 文件源码
def __init__(self, pos_x,pos_y,w_wdt,w_ht,parent=None):
        global name,home
        QtGui.QSystemTrayIcon.__init__(self, parent)
        #self.icon = QtGui.QLabel()
        icon_img = home+'/src/tray.png'
        self.right_menu = RightClickMenu(pos_x,pos_y,w_wdt,w_ht)
        self.setContextMenu(self.right_menu)

        self.activated.connect(self.onTrayIconActivated)
        self.p = QtGui.QPixmap(24,24)
        self.p.fill(QtGui.QColor("transparent"))
        painter = QtGui.QPainter(self.p)
        if os.path.exists(icon_img):
            self.setIcon(QtGui.QIcon(icon_img))
        else:
            self.setIcon(QtGui.QIcon(""))
        self.full_scr = 1
        del painter
项目:PH5    作者:PIC-IRIS    | 项目源码 | 文件源码
def paintEvent(self, e=None): 
        qp = QtGui.QPainter()
        qp.begin(self)
        if self.showPos: 
            # showing arrow (pointerWidget): intended to use for showing the point that user want to see the info 
            #    transparent if pre-created with no parent, 
            #    don't use because it show up too slow
            qp.setPen( QtGui.QPen(QtCore.Qt.red,3 ) )
            qp.drawLine(0, 0, 20, 20) 
            qp.drawLine(0, 0, 2, 10)
            qp.drawLine(0, 0, 10, 2 )
        else:
            # showing a tiny square at the select station(s)
            qp.setBrush(QtCore.Qt.red)
            qp.drawRect(0,0,self.rect().width(), self.rect().height())  # -1 or the right and bottom lines will be thinner than the rest
        qp.end()


##########################################
############### CLASS ####################
# Author: Lan
# Updated: 201410
# CLASS: FileParaDialog - GUI for setting the picture file's size and format
项目:PH5    作者:PIC-IRIS    | 项目源码 | 文件源码
def paintEvent(self, e):
        qp = QtGui.QPainter()

        qp.begin(self)  
        pen = QtGui.QPen(QtCore.Qt.blue, 1.7, QtCore.Qt.DashLine)
        qp.setFont(QtGui.QFont('Decorative', 9))
        qp.setPen(pen)
        #print "paintEvent"
        index = 0
        for lbl in self.canvas.labelPos:
            if lbl.has_key('y'):
                indent = 6*(6-len(lbl['text']))
                indent = indent if indent>0 else 0
                #print "%s => indent=%s" % (lbl['text'], indent)
                qp.drawText(1+indent, lbl['y']+5, lbl['text'])
            else:
                #print "text:'%s' len(lbl)=%s" % (lbl['text'], len(lbl['text']))
                qp.drawText(int(lbl['x']-len(lbl['text'])*3.5), self.height()-10, lbl['text'])
            index += 1

        qp.end()
项目:BTCeTrader    作者:ch3ll0v3k    | 项目源码 | 文件源码
def paintEvent(self, event):

        # -------------------------------------------------------------------
        Painter = QPainter()
        Painter.begin(self)

        # -------------------------------------------------------------------
        # Draw CROSS-MOUSE-POS
        if self.DRAW_CROSS:

            Painter.setPen( QPen( QColor(255,255,255, 255), 1, Qt.DashLine ) );
            Painter.drawPolyline( QPoint(self.MOUSE_X-600, self.MOUSE_Y), QPoint( self.MOUSE_X+600, self.MOUSE_Y) ); 
            Painter.drawPolyline( QPoint(self.MOUSE_X, self.MOUSE_Y-400), QPoint( self.MOUSE_X, self.MOUSE_Y+400) ); 

        # -------------------------------------------------------------------
        Painter.end();
        # -------------------------------------------------------------------

    # =======================================================================
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def export_Step_as_SVG(self):
        '''Export Petrinet and subnets to seperate SVG files'''
        filename = QtGui.QFileDialog.getSaveFileName( self, "Export Step as SVG", "%s/output/svg/"%(self.workingDir) , "*.svg" )
        if filename is "":
            return

        iterString = ""        
        for editor in self.editors:

            if editor is self.editors[0]:
                iterString = "_%s" %self.simulator.net
            else:
                iterString = "_%s" %editor.subnet

            generator = QtSvg.QSvgGenerator()
            newFilename = filename
            if ".svg" in filename:
                newFilename = filename.split(".svg")[0]+iterString+".svg"
            else:
                newFilename = filename+iterString+".svg"

            generator.setFileName(newFilename)            
            rect = editor.diagramScene.sceneRect()
            generator.setSize(QtCore.QSize(rect.width(), rect.height()))
            generator.setViewBox(QtCore.QRect(0, 0, rect.width(), rect.height()))
            generator.setTitle("%s Step %d"%(str(self.simulator.net), self.simulator.displayStep))
            painter = QtGui.QPainter()
            painter.begin(generator)
            editor.diagramScene.render( painter, source=rect , mode=QtCore.Qt.KeepAspectRatio)
            painter.end()

    #------------------------------------------------------------------------------------------------
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
def generatePicture(self):
            ## pre-computing a QPicture object allows paint() to run much more quickly,
            ## rather than re-drawing the shapes every time.
            self.picture = QtGui.QPicture()
            p = QtGui.QPainter(self.picture)
            p.setPen(pg.mkPen(color='r', width=0.4))  # 0.4 means w*2
            # w = (self.data[1][0] - self.data[0][0]) / 3.
            w = 0.2
            for (t, open, close, min, max) in self.data:
                p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
                if open > close:
                    p.setBrush(pg.mkBrush('g'))
                else:
                    p.setBrush(pg.mkBrush('r'))
                p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
            p.end()
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
def generatePicture(self):
        ## pre-computing a QPicture object allows paint() to run much more quickly,
        ## rather than re-drawing the shapes every time.
        self.picture = QtGui.QPicture()
        p = QtGui.QPainter(self.picture)
        p.setPen(pg.mkPen(color='r', width=0.4))  # 0.4 means w*2
        # w = (self.data[1][0] - self.data[0][0]) / 3.
        w = 0.2
        for (t, open, close, min, max) in self.data:
            p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
            if open > close:
                p.setBrush(pg.mkBrush('g'))
            else:
                p.setBrush(pg.mkBrush('r'))
            p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
        p.end()
项目:Comictagger    作者:dickloraine    | 项目源码 | 文件源码
def paintEvent (self, event):
        self.painter = QtGui.QPainter(self)
        self.painter.setRenderHint(QtGui.QPainter.Antialiasing)
        self.painter.drawPixmap(0, 0, self.desktopBg)
        self.painter.drawPixmap(0, 0, self.clientBgPixmap)
        self.painter.end()
项目:TPN    作者:myfavouritekk    | 项目源码 | 文件源码
def draw_predictions(file_path, predictions, class_index,
                     score_low, score_high):
    img = QtGui.QImage(file_path)
    painter = QtGui.QPainter(img)
    for i, pred in enumerate(predictions):
        if class_index > 0 and pred.class_index != class_index: continue
        if pred.score < score_low or pred.score > score_high: continue
        class_name = CLASS_NAMES[pred.class_index]
        x1, y1, x2, y2 = map(int, pred.bbox)
        # bbox
        painter.setPen(QtGui.QPen(PRESET_COLORS[pred.class_index], 10.0))
        # painter.setPen(QtGui.QPen(QtGui.QColor(0, 116, 217), 10.0))
        painter.setBrush(QtGui.QBrush())
        painter.drawRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1)
        # label background rect
        painter.setPen(QtGui.QPen(PRESET_COLORS[pred.class_index], 2.0))
        painter.setBrush(QtGui.QBrush(PRESET_COLORS[pred.class_index]))
        # painter.setPen(QtGui.QPen(QtGui.QColor(0, 116, 217), 2.0))
        # painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 116, 217)))
        if class_index > 0:
            painter.drawRect(x1, y1, min(x2 - x1 + 1, 100), 30)
        else:
            painter.drawRect(x1, y1, min(x2 - x1 + 1, 200), 30)
        # label text
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255)))
        painter.setBrush(QtGui.QBrush())
        painter.setFont(QtGui.QFont('Arial', 20, QtGui.QFont.Bold))
        if class_index > 0:
            painter.drawText(x1 + 4, y1 + 24, '{:.2f}'.format(pred.score))
        else:
            painter.drawText(x1 + 4, y1 + 24,
                             '{} {:.2f}'.format(class_name, pred.score))
    return img
项目:rec-attend-public    作者:renmengye    | 项目源码 | 文件源码
def paintEvent(self, event):
        # Create a QPainter that can perform draw actions within a widget or image
        qp = QtGui.QPainter()
        # Begin drawing in the application widget
        qp.begin(self)
        # Update scale
        self.updateScale(qp)
        # Determine the object ID to highlight
        self.getHighlightedObject(qp)
        # Draw the image first
        self.drawImage(qp)

        if self.enableDisparity and self.showDisparity:
            # Draw the disparities on top
            overlay = self.drawDisp(qp)
        else:
            # Draw the labels on top
            overlay = self.drawLabels(qp)
            # Draw the label name next to the mouse
            self.drawLabelAtMouse(qp)

        # Draw the zoom
        self.drawZoom(qp, overlay)

        # Thats all drawing
        qp.end()

        # Forward the paint event
        QtGui.QMainWindow.paintEvent(self,event)

    # Update the scaling
项目:rec-attend-public    作者:renmengye    | 项目源码 | 文件源码
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore
项目:EasyStorj    作者:lakewik    | 项目源码 | 文件源码
def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.drawPixmap(3, 3, self.picture)
项目:cityscapes-api    作者:renmengye    | 项目源码 | 文件源码
def paintEvent(self, event):
        # Create a QPainter that can perform draw actions within a widget or image
        qp = QtGui.QPainter()
        # Begin drawing in the application widget
        qp.begin(self)
        # Update scale
        self.updateScale(qp)
        # Determine the object ID to highlight
        self.getHighlightedObject(qp)
        # Draw the image first
        self.drawImage(qp)

        if self.enableDisparity and self.showDisparity:
            # Draw the disparities on top
            overlay = self.drawDisp(qp)
        else:
            # Draw the labels on top
            overlay = self.drawLabels(qp)
            # Draw the label name next to the mouse
            self.drawLabelAtMouse(qp)

        # Draw the zoom
        self.drawZoom(qp, overlay)

        # Thats all drawing
        qp.end()

        # Forward the paint event
        QtGui.QMainWindow.paintEvent(self,event)

    # Update the scaling
项目:cityscapes-api    作者:renmengye    | 项目源码 | 文件源码
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore
项目:WxNeteaseMusic    作者:yaphone    | 项目源码 | 文件源码
def paintEvent(self, event):
            qp = QtGui.QPainter()
            qp.begin(self)
            self.drawText(event, qp)
            qp.end()
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def image(self):
        pixmap = QtGui.QPixmap(250, 250)
        pixmap.fill(QtCore.Qt.transparent)
        painter = QtGui.QPainter(pixmap)
        painter.setPen(QtGui.QPen(QtCore.Qt.black, 8))
        painter.translate(125, 125)
        painter.drawPolyline(self.myPolygon)
        return pixmap
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def createColorToolButtonIcon(self, imageFile, color):
        pixmap = QtGui.QPixmap(50, 80)
        pixmap.fill(QtCore.Qt.transparent)
        painter = QtGui.QPainter(pixmap)
        image = QtGui.QPixmap(imageFile)
        target = QtCore.QRect(0, 0, 50, 60)
        source = QtCore.QRect(0, 0, 42, 42)
        painter.fillRect(QtCore.QRect(0, 60, 50, 80), color)
        painter.drawPixmap(target, image, source)
        painter.end()

        return QtGui.QIcon(pixmap)
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def createColorIcon(self, color):
        pixmap = QtGui.QPixmap(20, 20)
        painter = QtGui.QPainter(pixmap)
        painter.setPen(QtCore.Qt.NoPen)
        painter.fillRect(QtCore.QRect(0, 0, 20, 20), color)
        painter.end()

        return QtGui.QIcon(pixmap)