initial commit
This commit is contained in:
commit
d559fc128e
10 changed files with 150 additions and 0 deletions
87
task1.py
Normal file
87
task1.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import sys
|
||||
from PyQt6.QtGui import QPixmap
|
||||
from PyQt6.QtWidgets import (
|
||||
QApplication, QMainWindow,
|
||||
QWidget, QLabel,
|
||||
QHBoxLayout, QVBoxLayout
|
||||
)
|
||||
from PyQt6.QtCore import Qt
|
||||
|
||||
|
||||
class TaskOne(QMainWindow):
|
||||
def __init__(self, path_to_image: str):
|
||||
super().__init__()
|
||||
self.original_pixmap = QPixmap(path_to_image)
|
||||
self._init_ui()
|
||||
self.setFixedSize(900, 250)
|
||||
|
||||
def _init_ui(self):
|
||||
root = QWidget(self)
|
||||
main_layout = QHBoxLayout(root)
|
||||
|
||||
# Отступы как на макете
|
||||
main_layout.setSpacing(15)
|
||||
main_layout.setContentsMargins(15, 15, 15, 15)
|
||||
|
||||
# ---------- Фото ----------
|
||||
self.image_label = QLabel()
|
||||
self.image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
self.image_label.setMinimumSize(180, 180)
|
||||
self.image_label.setStyleSheet("border: 1px solid black;")
|
||||
|
||||
# ---------- Текстовая информация ----------
|
||||
info_layout = QVBoxLayout()
|
||||
info_layout.setSpacing(5)
|
||||
|
||||
title = QLabel("Категория товара | Наименование товара")
|
||||
title.setStyleSheet("font-weight: bold;")
|
||||
|
||||
info_layout.addWidget(title)
|
||||
info_layout.addWidget(QLabel("Описание товара:"))
|
||||
info_layout.addWidget(QLabel("Производитель:"))
|
||||
info_layout.addWidget(QLabel("Поставщик:"))
|
||||
info_layout.addWidget(QLabel("Цена:"))
|
||||
info_layout.addWidget(QLabel("Единица измерения:"))
|
||||
info_layout.addWidget(QLabel("Количество на складе:"))
|
||||
info_layout.addStretch()
|
||||
|
||||
# ---------- Скидка ----------
|
||||
discount_label = QLabel("Действующая\nскидка")
|
||||
discount_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
discount_label.setFixedWidth(120)
|
||||
discount_label.setStyleSheet("""
|
||||
QLabel {
|
||||
border: 1px solid black;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
|
||||
# ---------- Добавление в основной layout ----------
|
||||
main_layout.addWidget(self.image_label, stretch=0)
|
||||
main_layout.addLayout(info_layout, stretch=1)
|
||||
main_layout.addWidget(discount_label, stretch=0)
|
||||
|
||||
self.setCentralWidget(root)
|
||||
self._update_pixmap()
|
||||
|
||||
def resizeEvent(self, event):
|
||||
self._update_pixmap()
|
||||
super().resizeEvent(event)
|
||||
|
||||
def _update_pixmap(self):
|
||||
if self.original_pixmap.isNull():
|
||||
return
|
||||
|
||||
scaled = self.original_pixmap.scaled(
|
||||
self.image_label.size(),
|
||||
Qt.AspectRatioMode.KeepAspectRatio,
|
||||
Qt.TransformationMode.SmoothTransformation
|
||||
)
|
||||
self.image_label.setPixmap(scaled)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = TaskOne("apple.webp")
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
Loading…
Add table
Add a link
Reference in a new issue