-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_Qt.py
More file actions
62 lines (43 loc) · 1.71 KB
/
Copy pathtesting_Qt.py
File metadata and controls
62 lines (43 loc) · 1.71 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sys
from PySide6.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QApplication, QLabel
from PySide6.QtGui import QPixmap
from PySide6.QtCore import Qt
# Description: This script builds a small QApplication GUI with a label to demonstrate blurred rendering of
# low-resolution pixel art.
class ScaledLabel(QLabel):
def __init__(self, *args, **kwargs):
QLabel.__init__(self)
self._pixmap = self.pixmap()
def resizeEvent(self, event):
self.setPixmap(self._pixmap)
def setPixmap(self, pixmap):
if not pixmap:
return
self._pixmap = pixmap
return (QLabel.setPixmap(self,
self._pixmap.scaled(self.frameSize(),
Qt.KeepAspectRatio,
Qt.FastTransformation)))
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# Specify the path to the pixel art .png file to display:
path_to_png = 'pixel_art.png'
# Create an instance of the QLabel class:
self.my_scaled_label = ScaledLabel()
# Display the pixel art as a pixmap in the label:
self.my_scaled_label.setPixmap(QPixmap(path_to_png))
# Place the label & buttons in a vertical layout:
layout_v = QVBoxLayout()
layout_v.addWidget(self.my_scaled_label)
# Create a placeholder widget to hold the layout.
widget = QWidget()
widget.setLayout(layout_v)
# Set the central widget of the main window:
self.setCentralWidget(widget)
# Run the QApplication:
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec()
print('app finished')