-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdiarea_pixmap.py
43 lines (28 loc) · 1.11 KB
/
mdiarea_pixmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import sys
from PyQt4.QtCore import Qt
from PyQt4.QtGui import *
class MDIArea(QMdiArea):
def __init__(self, background_pixmap, parent = None):
QMdiArea.__init__(self, parent)
self.background_pixmap = background_pixmap
self.centered = False
def paintEvent(self, event):
painter = QPainter()
painter.begin(self.viewport())
if not self.centered:
painter.drawPixmap(0, 0, self.width(), self.height(), self.background_pixmap)
else:
painter.fillRect(event.rect(), self.palette().color(QPalette.Window))
x = (self.width() - self.display_pixmap.width())/2
y = (self.height() - self.display_pixmap.height())/2
painter.drawPixmap(x, y, self.display_pixmap)
painter.end()
def resizeEvent(self, event):
self.display_pixmap = self.background_pixmap.scaled(event.size(), Qt.KeepAspectRatio)
if __name__ == "__main__":
app = QApplication(sys.argv)
m = MDIArea(QPixmap("Death_Valley_Dunes.jpg"))
m.centered = True
m.show()
sys.exit(app.exec_())