2017-02-24 1 views
0

나는 내 Qpainter의 크기를 변경하려고했는데 내가 어떻게 도와 줄 수 있는지 알아낼 수 없다. 내 코드는 내가 온라인으로 보았고 내가 필요로하는 코드가 포함되어 있기 때문에 알아낼 수 없다. 당신의 도움을 필요로하지 않는 다른 코드의 똥 소리.파이썬 Qpainter 크기 조정

import sys 
import os 
from PyQt4.QtCore import QSize, QTimer 
from PyQt4.QtGui import QApplication,QGraphicsRectItem , QMainWindow, QPushButton, QWidget, QIcon, QLabel, QPainter, QPixmap, QMessageBox, QAction, QKeySequence, QFont, QFontMetrics, QMovie 
from PyQt4 import QtGui 


class UIWindow(QWidget): 
    def __init__(self, parent=None): 
     super(UIWindow, self).__init__(parent) 
     self.resize(QSize(400, 450)) 

    def paintEvent(self, event): 
     painter = QPainter(self) 
     painter.drawPixmap(self.rect(), QPixmap("Images\Image.png")) 
     painter.move(0,0) 
     painter.resize(950,270) 




class MainWindow(QMainWindow,): 
    def __init__(self, parent=None): 
     super(MainWindow, self).__init__(parent) 
     self.setGeometry(490, 200, 950, 620) 
     self.setFixedSize(950, 620) 
     self.startUIWindow() 
     self.setWindowIcon(QtGui.QIcon('Images\Logo.png')) 

    def startUIWindow(self): 
     self.Window = UIWindow(self) 
     self.setWindowTitle("pythonw") 
     self.setCentralWidget(self.Window) 
     self.show() 

if __name__ == '__main__': 
    app = QApplication(sys.argv) 
    w = MainWindow() 
    sys.exit(app.exec_()) 
+0

을 'QPainter'는'move()'메소드를 가지고 있지 않습니다. 정확히 무엇을하고 싶습니까? – eyllanesc

+0

QPainter는 위젯을 그리는 것을 담당하는 클래스입니다. 위젯이나 브러시가 아닙니다. – eyllanesc

+0

@eyllanesc 이미지가 중앙의 프로그램이 아닌 다양한 상단에 나타나도록 왜곡되어 있습니다. – Tyrell

답변

2

drawPixmap 기능은 첫번째 파라미터로 그려 될 사각형, 즉 (0, 0, 폭, 높이)

def paintEvent(self, event): 
    painter = QPainter(self) 
    pixmap = QPixmap("Images\Image.png") 
    painter.drawPixmap(QRect(0, 0, pixmap.width(), pixmap.height()), pixmap) 

전체 코드 필요

import sys 
import os 
from PyQt4.QtCore import QSize, QTimer, QRect 
from PyQt4.QtGui import QApplication,QGraphicsRectItem , QMainWindow, QPushButton, QWidget, QIcon, QLabel, QPainter, QPixmap, QMessageBox, QAction, QKeySequence, QFont, QFontMetrics, QMovie 
from PyQt4 import QtGui 


class UIWindow(QWidget): 
    def __init__(self, parent=None): 
     super(UIWindow, self).__init__(parent) 
     self.resize(QSize(400, 450)) 

    def paintEvent(self, event): 
     painter = QPainter(self) 
     pixmap = QPixmap("Images\Image.png") 
     painter.drawPixmap(QRect(0, 0, pixmap.width(), pixmap.height()), pixmap) 


class MainWindow(QMainWindow,): 
    def __init__(self, parent=None): 
     super(MainWindow, self).__init__(parent) 
     self.setGeometry(490, 200, 950, 620) 
     self.setFixedSize(950, 620) 
     self.startUIWindow() 

    def startUIWindow(self): 
     self.Window = UIWindow(self) 
     self.setWindowTitle("pythonw") 
     self.setCentralWidget(self.Window) 
     self.show() 

if __name__ == '__main__': 
    app = QApplication(sys.argv) 
    w = MainWindow() 
    sys.exit(app.exec_()) 
+0

정말 고맙습니다. – Tyrell

관련 문제