2016-05-01 6 views
1

私はPyQTプログラマーで迷っています。 SVG画像をフルスクリーンで表示したいのですが、画像のスケールと位置を設定し、残りの部分を黒色で設定する必要があります。 私はQSvgWidgetと通常のQWidgetを互いの上に使用しますが、2つのプロセスと2つの別々のウィンドウとして実行されるため、良い解決策ではありません。 一つだけのウィジェットPyQTでQSvgWidgetを使用してSVGイメージのサイズを全画面に設定しますか?

import sys, os 
from PyQt4 import QtGui, QtSvg 

class Display(QtSvg.QSvgWidget): 
    def __init__(self, parent=None): 
     super(Display, self).__init__(parent) 

def main(): 
    app = QtGui.QApplication(sys.argv) 
    black = QtGui.QWidget() #setting background with widget 
    black.showFullScreen() 
    form = Display() 
    form.setWindowTitle("Display SVG Layer") 

    form.showFullScreen() 

    form.setStyleSheet("background-color:black;") 
    form.load("E:\example.svg") 

    form.move(100,0) 
    form.resize(1900,1000) 

    app.exec_() 

if __name__ == '__main__': 
    main() 

答えて

0

でこれを作る方法を教えてもらえますがQGraphicsViewQGraphicsScene使用することができ、おそらく:

class MyGraphicsView(QGraphicsView): 
    def __init__(self, w, h, parent=None): 
     QGraphicsView.__init__(self, parent) 

     self.setGeometry(0, 0, w, h)    # screen size 

class MyGraphicsScene(QGraphicsScene): 
    def __init__(self, w, h, parent = None): 
     QGraphicsScene.__init__(self,parent) 

     self.setSceneRect(0, 0, w, h)   # screen size 

     self.backgroundPen = QPen(QColor(Qt.black)) 
     self.backgroundBrush = QBrush(QColor(Qt.black)) 

     self.textPen = QPen(QColor(Qt.lightGray)) 
     self.textPen.setWidth(1) 
     self.textBrush = QBrush(QColor(Qt.lightGray)) 
     self.textFont = QFont("Helvetica", 14,) 

     # paint the background 
     self.addRect(0,0,self.width(), self.height(), self.backgroundPen, self.backgroundBrush) 

     # paint the svg-title 
     self.svgTitle = self.addSimpleText('Display SVG Layer', self.textFont) 
     self.svgTitle.setPen(self.textPen) 
     self.svgTitle.setBrush(self.textBrush) 
     self.svgTitle.setPos(200,75) 

     # paint the svg 
     self.svgItem = QGraphicsSvgItem('./example.svg') 
     ''' 
     edit: 
     if necessary, get the size of the svgItem to calculate 
     scale factor and position 
     ''' 
     self.svgSize = self.svgItem.renderer().defaultSize() 
     self.svgItem.setScale(0.25)      # scale the svg to an appropriate size 
     self.addItem(self.svgItem) 
     self.svgItem.setPos(200, 125) 

if __name__ == '__main__': 
    app = QApplication(sys.argv) 

    screen_size = app.primaryScreen().size()   
    width = screen_size.width() 
    height = screen_size.height() 

    graphicsScene = MyGraphicsScene(width, height) 

    graphicsView = MyGraphicsView(width, height) 
    graphicsView.setScene(graphicsScene) 
    graphicsView.show() 
    app.exec_() 
+0

おかげであなたはスケールファクタを計算するsourcesizeが必要な場合、私はこの – MMM

+0

をしようとすると、位置は私の答えの編集を参照してください –

関連する問題