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


Python Qt.QTransform类代码示例

本文整理汇总了Python中PyQt5.Qt.QTransform的典型用法代码示例。如果您正苦于以下问题:Python QTransform类的具体用法?Python QTransform怎么用?Python QTransform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: resolve_fill

    def resolve_fill(self, rect, pdf_system, qt_system):
        '''
        Qt's paint system does not update brushOrigin when using
        TexturePatterns and it also uses TexturePatterns to emulate gradients,
        leading to brokenness. So this method allows the paint engine to update
        the brush origin before painting an object. While not perfect, this is
        better than nothing. The problem is that if the rect being filled has a
        border, then QtWebKit generates an image of the rect size - border but
        fills the full rect, and there's no way for the paint engine to know
        that and adjust the brush origin.
        '''
        if not hasattr(self, 'last_fill') or not self.current_state.do_fill:
            return

        if isinstance(self.last_fill.brush, TexturePattern):
            tl = rect.topLeft()
            if tl == self.last_fill.origin:
                return

            matrix = (QTransform.fromTranslate(tl.x(), tl.y())
                * pdf_system * qt_system.inverted()[0])

            pat = TexturePattern(None, matrix, self.pdf, clone=self.last_fill.brush)
            pattern = self.pdf.add_pattern(pat)
            self.pdf.apply_fill(self.last_fill.color, pattern)
开发者ID:AtulKumar2,项目名称:calibre,代码行数:25,代码来源:graphics.py

示例2: __init__

    def __init__(self, file_object, page_width, page_height, left_margin,
                 top_margin, right_margin, bottom_margin, width, height,
                 errors=print, debug=print, compress=True,
                 mark_links=False):
        QPaintEngine.__init__(self, self.FEATURES)
        self.file_object = file_object
        self.compress, self.mark_links = compress, mark_links
        self.page_height, self.page_width = page_height, page_width
        self.left_margin, self.top_margin = left_margin, top_margin
        self.right_margin, self.bottom_margin = right_margin, bottom_margin
        self.pixel_width, self.pixel_height = width, height
        # Setup a co-ordinate transform that allows us to use co-ords
        # from Qt's pixel based co-ordinate system with its origin at the top
        # left corner. PDF's co-ordinate system is based on pts and has its
        # origin in the bottom left corner. We also have to implement the page
        # margins. Therefore, we need to translate, scale and reflect about the
        # x-axis.
        dy = self.page_height - self.top_margin
        dx = self.left_margin
        sx =  (self.page_width - self.left_margin -
                            self.right_margin) / self.pixel_width
        sy =  (self.page_height - self.top_margin -
                            self.bottom_margin) / self.pixel_height

        self.pdf_system = QTransform(sx, 0, 0, -sy, dx, dy)
        self.graphics = Graphics(self.pixel_width, self.pixel_height)
        self.errors_occurred = False
        self.errors, self.debug = errors, debug
        self.fonts = {}
        self.current_page_num = 1
        self.current_page_inited = False
        self.content_written_to_current_page = False
        self.qt_hack, err = plugins['qt_hack']
        if err:
            raise RuntimeError('Failed to load qt_hack with err: %s'%err)
开发者ID:TeddyHartanto,项目名称:calibre,代码行数:35,代码来源:engine.py

示例3: drawContents

 def drawContents(self, painter):
     self.drawn_once = True
     painter.save()
     painter.setPen(Qt.black)
     painter.setRenderHint(painter.TextAntialiasing, True)
     painter.setRenderHint(painter.Antialiasing, True)
     f = painter.font()
     f.setPixelSize(18)
     painter.setFont(f)
     t = QTransform()
     t.translate(330, 450)
     painter.setTransform(t)
     painter.rotate(-98)
     left_margin = 25
     if iswindows:
         # On windows Qt cannot anti-alias rotated text
         p = QPainterPath()
         p.addText(left_margin, 0, f, self.message())
         painter.fillPath(p, QBrush(Qt.black))
     else:
         painter.drawText(left_margin, 0, self.message())
     painter.restore()
开发者ID:davidfor,项目名称:calibre,代码行数:22,代码来源:splash_screen.py

示例4: convert_brush

    def convert_brush(self, brush, brush_origin, global_opacity,
                      pdf_system, qt_system):
        # Convert a QBrush to PDF operators
        style = brush.style()
        pdf = self.pdf

        pattern = color = pat = None
        opacity = global_opacity
        do_fill = True

        matrix = (QTransform.fromTranslate(brush_origin.x(), brush_origin.y())
                  * pdf_system * qt_system.inverted()[0])
        vals = list(brush.color().getRgbF())
        self.brushobj = None

        if style <= Qt.DiagCrossPattern:
            opacity *= vals[-1]
            color = vals[:3]

            if style > Qt.SolidPattern:
                pat = QtPattern(style, matrix)

        elif style == Qt.TexturePattern:
            pat = TexturePattern(brush.texture(), matrix, pdf)
            if pat.paint_type == 2:
                opacity *= vals[-1]
                color = vals[:3]

        elif style == Qt.LinearGradientPattern:
            pat = LinearGradientPattern(brush, matrix, pdf, self.page_width_px,
                                        self.page_height_px)
            opacity *= pat.const_opacity
        # TODO: Add support for radial/conical gradient fills

        if opacity < 1e-4 or style == Qt.NoBrush:
            do_fill = False
        self.brushobj = Brush(brush_origin, pat, color)

        if pat is not None:
            pattern = pdf.add_pattern(pat)
        return color, opacity, pattern, do_fill
开发者ID:AtulKumar2,项目名称:calibre,代码行数:41,代码来源:graphics.py

示例5: rotate_image

def rotate_image(img, degrees):
    t = QTransform()
    t.rotate(degrees)
    return image_from_data(img).transformed(t)
开发者ID:x007007007,项目名称:calibre,代码行数:4,代码来源:img.py

示例6: update

    def update(self):

        restant = 360
        i = 0
        #self.my_scene.clear()
        for item in self.pie_items :
            self.my_scene.removeItem(item)
        self.pie_items = []
        self.scene().setSceneRect(QRectF(0,0,self.frameSize().width(),self.frameSize().height()))
        #print ('size',self.scene().sceneRect())
        #proxy = QGraphicsProxyWidget ()

        for item in self.data :
            if (i==len(self.data)-1 ):
                angle = restant
            else:
                try : 
                    angle = int(360*item[self.c_box.currentText()]/self.total_value[self.c_box.currentText()])
                except ZeroDivisionError:
                    angle = 0 
                    
            ellipse = Section(0,0,self.size_pie.width(),self.size_pie.height())

            y = (self.parent().size().height()-self.size_pie.height())/2.0
            x_pie = ((self.parent().size().width()/2.0)-self.size_pie.height())/2.0
            ellipse.setPos(x_pie,y)
 
            ellipse.setStartAngle(16*(360-restant))
            ellipse.setSpanAngle(angle*16)
            ellipse.setBrush(item['color'])
            self.my_scene.addItem(ellipse)
            self.pie_items.append(ellipse)
            # text pourcentage a afficher dans les portions de disque
            try :
                v = (item[self.c_box.currentText()]/self.total_value[self.c_box.currentText()])*100
            except ZeroDivisionError :
                v = 0
            text = QGraphicsSimpleTextItem("{0:5.2f}".format(v)+"%")
            trans = QTransform().translate(x_pie+self.size_pie.width()/2.0,y+self.size_pie.height()/2.0).rotate(((360-restant)+angle/2.0)*-1)
            pts = trans.map(QPointF(self.size_pie.width()/3.0,0))
            text.setPos(pts.x(),pts.y())
            self.my_scene.addItem(text)            
            self.pie_items.append(text)
            
            #libelle 
            rect = QGraphicsRectItem(0,0,10,10)
            x = x_pie + self.size_pie.width()+ self.space 
            interval_height = (self.parent().size().height()-self.margin['top']-self.margin['bottom'])/(len(self.data)+1)
            rect.setPos(QPointF(x,self.margin['top']+((i+1)*interval_height)))
            rect.setBrush(item['color'])
            self.my_scene.addItem(rect)
            self.pie_items.append(rect)
            text = QGraphicsSimpleTextItem(item['label']+ " ("+str(int(item[self.c_box.currentText()]))+")")
            pts = rect.pos()
            transform = QTransform().translate(30, 0)
            pts = transform.map(pts)
            text.setPos(pts)            
            self.my_scene.addItem(text)
            self.pie_items.append(text)
            restant = restant - angle
            i +=1

     #   self.fitInView(self.scene.sceneRect())
开发者ID:cyril711,项目名称:git-MythicWar,代码行数:63,代码来源:pie_chart.py

示例7: PdfEngine

class PdfEngine(QPaintEngine):

    FEATURES = QPaintEngine.AllFeatures & ~(
        QPaintEngine.PorterDuff | QPaintEngine.PerspectiveTransform |
        QPaintEngine.ObjectBoundingModeGradients |
        QPaintEngine.RadialGradientFill |
        QPaintEngine.ConicalGradientFill
    )

    def __init__(self, file_object, page_width, page_height, left_margin,
                 top_margin, right_margin, bottom_margin, width, height,
                 errors=print, debug=print, compress=True,
                 mark_links=False, opts=None):
        QPaintEngine.__init__(self, self.FEATURES)
        self.file_object = file_object
        self.compress, self.mark_links = compress, mark_links
        self.page_height, self.page_width = page_height, page_width
        self.left_margin, self.top_margin = left_margin, top_margin
        self.right_margin, self.bottom_margin = right_margin, bottom_margin
        self.pixel_width, self.pixel_height = width, height
        # Setup a co-ordinate transform that allows us to use co-ords
        # from Qt's pixel based co-ordinate system with its origin at the top
        # left corner. PDF's co-ordinate system is based on pts and has its
        # origin in the bottom left corner. We also have to implement the page
        # margins. Therefore, we need to translate, scale and reflect about the
        # x-axis.
        dy = self.page_height - self.top_margin
        dx = self.left_margin
        sx =  (self.page_width - self.left_margin -
                            self.right_margin) / self.pixel_width
        sy =  (self.page_height - self.top_margin -
                            self.bottom_margin) / self.pixel_height

        self.pdf_system = QTransform(sx, 0, 0, -sy, dx, dy)
        self.graphics = Graphics(self.pixel_width, self.pixel_height)
        self.errors_occurred = False
        self.errors, self.debug = errors, debug
        self.fonts = {}
        self.current_page_num = 1
        self.current_page_inited = False
        self.content_written_to_current_page = False
        self.qt_hack, err = plugins['qt_hack']
        self.has_footers = opts is not None and (opts.pdf_page_numbers or opts.pdf_footer_template is not None)
        self.has_headers = opts is not None and opts.pdf_header_template is not None
        self.header_height = (opts.margin_top or 0) if opts else 0
        self.footer_height = (opts.margin_bottom) or 0 if opts else 0
        if err:
            raise RuntimeError('Failed to load qt_hack with err: %s'%err)

    def apply_graphics_state(self):
        self.graphics(self.pdf_system, self.painter())

    def resolve_fill(self, rect):
        self.graphics.resolve_fill(rect, self.pdf_system,
                                   self.painter().transform())

    @property
    def do_fill(self):
        return self.graphics.current_state.do_fill

    @property
    def do_stroke(self):
        return self.graphics.current_state.do_stroke

    def init_page(self):
        self.content_written_to_current_page = False
        self.pdf.transform(self.pdf_system)
        self.pdf.apply_fill(color=(1, 1, 1))  # QPainter has a default background brush of white
        self.graphics.reset()
        self.pdf.save_stack()
        self.current_page_inited = True

    def begin(self, device):
        if not hasattr(self, 'pdf'):
            try:
                self.pdf = PDFStream(self.file_object, (self.page_width,
                        self.page_height), compress=self.compress,
                                     mark_links=self.mark_links,
                                     debug=self.debug)
                self.graphics.begin(self.pdf)
            except:
                self.errors(traceback.format_exc())
                self.errors_occurred = True
                return False
        return True

    def end_page(self, is_last_page=False):
        if self.current_page_inited:
            self.pdf.restore_stack()
            drop_page = is_last_page and not self.content_written_to_current_page
            self.pdf.end_page(drop_page=drop_page)
            self.current_page_inited = False
            self.current_page_num += 0 if drop_page else 1
        return self.content_written_to_current_page

    def end(self):
        try:
            self.end_page()
            self.pdf.end()
        except:
#.........这里部分代码省略.........
开发者ID:Mymei2,项目名称:calibre,代码行数:101,代码来源:engine.py

示例8: __call__

 def __call__(self, canvas):
     img = canvas.current_image
     m = QTransform()
     m.rotate(90)
     return img.transformed(m, Qt.SmoothTransformation)
开发者ID:Ralnoc,项目名称:calibre,代码行数:5,代码来源:canvas.py

示例9: update

    def update(self):

        
        i = 0
        #self.my_scene.clear()
        for item in self.histo_items :
            self.my_scene.removeItem(item)
        self.histo_items = []
        self.scene().setSceneRect(QRectF(0,0,self.frameSize().width(),self.frameSize().height()))

        max = -1
        for value in self.data.values():
            if value[self.c_box.currentText()] > max:
                max = value[self.c_box.currentText()]


        size_text_number = QGraphicsTextItem(str(max)).boundingRect().width()+10
        interval= self.parent().size().height()-self.margin['top']-self.margin['bottom']
        interval = interval /len(self.data)
        

        temp = "aaaaaaaaaaaaaaaaa"
        if len(temp)> self.max_length_text:
            data = temp[:self.max_length_text]+"."
        else :
            data = temp
        self.size_text_width = QGraphicsTextItem(data).boundingRect().width()+10
        #print ('width:',self.size_text_width)
        horizontal_size = self.parent().size().width()- self.margin['left']- self.margin['right']-self.size_text_width- size_text_number
        try:
            ratio = horizontal_size/ max
        except ZeroDivisionError :
            ratio = 0


        i = 0
        for groupe,value in zip(self.data.keys(),self.data.values()) :

            if self.c_box.currentText() == "warrior":
                title_str = 'Nombre de Heros'
                bar_all = QGraphicsRectItem(0,self.margin['top'],value['warrior']*ratio,interval*0.8)
                bar_all.setPos(self.size_text_width,interval*0.2+(i*interval))
                gradient = QLinearGradient(QPointF(bar_all.rect().width()/2,0),QPointF(bar_all.rect().width()/2,bar_all.rect().height()+self.margin['top']))
                gradient.setColorAt(0,QColor('white'))
                gradient.setColorAt(1,QColor('red'))
                brush = QBrush(gradient)            
                #brush.setTexture(QPixmap(":/textures/"+groupe.attribs['color']))
                bar_all.setBrush(brush)
                self.my_scene.addItem(bar_all)
                self.histo_items.append(bar_all)
    
                bar_alive = QGraphicsRectItem(0,self.margin['top'],value['alive']*ratio,interval*0.8)
                bar_alive.setPos(self.size_text_width,interval*0.2+(i*interval))
                gradient = QLinearGradient(QPointF(bar_alive.rect().width()/2,0),QPointF(bar_alive.rect().width()/2,bar_alive.rect().height()+self.margin['top']))
    #             gradient.setStart(QPointF(0.5,0))
    #             gradient.setStop(QPointF(0.5,1))
                gradient.setColorAt(0,QColor('white'))
                gradient.setColorAt(1,QColor('green'))
                brush = QBrush(gradient)
                
                bar_alive.setBrush(brush)
                self.my_scene.addItem(bar_alive)
                self.histo_items.append(bar_alive)
    
                text_nb_warriors= QGraphicsTextItem(str(value['warrior']))
                text_nb_warriors.setDefaultTextColor(QColor('green'))
                trans = QTransform().translate(bar_all.pos().x()+bar_all.rect().width()+10,interval*0.2+(i*interval)+self.margin['top'])
                pts = trans.map(QPointF(0,0.0))
                text_nb_warriors.setPos(pts.x(),pts.y())
                self.my_scene.addItem(text_nb_warriors)            
                self.histo_items.append(text_nb_warriors)


            #bar ranl
            elif self.c_box.currentText()== "rank":
                title_str = "Rank Moyen"
                bar_rank = QGraphicsRectItem(0,self.margin['top'],value['rank']*ratio,interval*0.8)
                bar_rank.setPos(self.size_text_width, interval*0.2+(i*interval))
                gradient = QLinearGradient(QPointF(bar_rank.rect().width()/2,0),QPointF(bar_rank.rect().width()/2,bar_rank.rect().height()+self.margin['top']))
    #             gradient.setStart(QPointF(0.5,0))
    #             gradient.setStop(QPointF(0.5,1))
                gradient.setColorAt(0,QColor('white'))
                gradient.setColorAt(1,QColor('red'))
                brush = QBrush(gradient)
                
                bar_rank.setBrush(brush)
                self.my_scene.addItem(bar_rank)
                self.histo_items.append(bar_rank)
    
                # value
                text_rank = QGraphicsTextItem("{0:1.1f}".format(value['rank']))
                text_rank.setDefaultTextColor(QColor('red'))
                trans = QTransform().translate(bar_rank.pos().x()+bar_rank.rect().width()+10,interval*0.2+(i*interval)+self.margin['top'])
                pts = trans.map(QPointF(0,0.0))
                text_rank.setPos(pts.x(),pts.y())
                self.my_scene.addItem(text_rank)            
                self.histo_items.append(text_rank)
    

            else:
#.........这里部分代码省略.........
开发者ID:cyril711,项目名称:git-MythicWar,代码行数:101,代码来源:histo_chart.py


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