python 调整 Qpainter 的大小
python resizing a 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_())
drawPixmap 函数需要将要绘制的矩形作为第一个参数,即 (0, 0, width, height)
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_())
我曾尝试更改我的 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_())
drawPixmap 函数需要将要绘制的矩形作为第一个参数,即 (0, 0, width, height)
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_())