From 90b494adc4f08e2a58739ffe4b62ab0bd82c1308 Mon Sep 17 00:00:00 2001 From: MarcusStill <69536339+MarcusStill@users.noreply.github.com> Date: Sun, 13 Sep 2026 16:47:33 +0000 Subject: [PATCH] Apply Windows 10/11 QSS styling to PySide6 GUI\n\n- Add `files/style.qss` with Windows 10/11 aesthetics.\n- Update `main.py` to load and apply `style.qss` handling errors.\n- Prevent `MainWindow` from garbage collection destruction.\n- Update deprecated `.exec_()` method calls to `.exec()`. --- files/style.qss | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 26 +++++++++++++++++-------- 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 files/style.qss diff --git a/files/style.qss b/files/style.qss new file mode 100644 index 0000000..c954d73 --- /dev/null +++ b/files/style.qss @@ -0,0 +1,52 @@ +/* style.qss */ +QMainWindow, QDialog { + background-color: #F3F3F3; +} + +QWidget { + font-family: "Segoe UI", sans-serif; + font-size: 10pt; + color: #000000; +} + +QPushButton { + background-color: #E1E1E1; + border: 1px solid #ADADAD; + padding: 5px 15px; + border-radius: 4px; +} + +QPushButton:hover { + background-color: #E5F1FB; + border: 1px solid #0078D4; +} + +QPushButton:pressed { + background-color: #CCE4F7; + border: 1px solid #005499; +} + +QLineEdit, QTextEdit, QComboBox, QDateEdit { + background-color: #FFFFFF; + border: 1px solid #CCCCCC; + padding: 3px; + border-radius: 2px; +} + +QLineEdit:focus, QTextEdit:focus, QComboBox:focus, QDateEdit:focus { + border: 1px solid #0078D4; +} + +QTableView, QTableWidget { + background-color: #FFFFFF; + alternate-background-color: #F9F9F9; + border: 1px solid #CCCCCC; + gridline-color: #E0E0E0; +} + +QHeaderView::section { + background-color: #F0F0F0; + padding: 4px; + border: 1px solid #CCCCCC; + font-weight: bold; +} diff --git a/main.py b/main.py index c7f54d0..769e1b2 100644 --- a/main.py +++ b/main.py @@ -216,13 +216,13 @@ def show_main_window(): None: Функция не возвращает значений, а лишь выполняет отображение главного окна. """ window = MainWindow() + QtWidgets.QApplication.instance().main_window = window window.showMaximized() user_full_name = f"{system.user.last_name} {system.user.first_name}" window.setWindowTitle( f"PyMASL ver. {system.software_version}. Пользователь: {user_full_name}. БД: {system.database}" ) window.main_button_all_sales() - window.exec_() @@ -429,7 +429,7 @@ def edit_client_in_sale(self) -> None: # Сохраняем параметры данных об уже существующем клиенте system.client_update = 1 logger.info(f"Обновляем инф. клиента {system.client_id}") - client.exec_() + client.exec() def adding_new_client_to_sale(self) -> None: """ @@ -2344,7 +2344,7 @@ def open_pay_form(self, txt): # Передаем текст в форму PayForm pay.setText(txt) - res: int = pay.exec_() + res: int = pay.exec() # если пользователь нажал крестик или кнопку Escape, # то по-умолчанию возвращается QDialog.Rejected if res == QDialog.Rejected: @@ -2523,7 +2523,7 @@ def get_slip(self) -> None: slip.ui.lineEdit.setText(rrn_value) slip.ui.textEdit.setText(load_slip) slip.show() - slip.exec_() + slip.exec() class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): @@ -2835,7 +2835,7 @@ def main_edit_client(self) -> None: # Сохраняем параметры данных об уже существующем клиенте system.client_update = 1 logger.info(f"Обновляем информацию о клиенте") - client.exec_() + client.exec() def main_filter_clear(self) -> None: """ @@ -3130,7 +3130,7 @@ def main_search_selected_sale(self) -> None: system.sale_id = int(sale_number) system.sale_tickets = client_in_sale logger.debug(f"Билеты сохраненной продажи: {system.sale_tickets}") - sale.exec_() + sale.exec() @logger_wraps(entry=True, exit=True, level="DEBUG") def main_button_all_sales(self) -> None: @@ -3316,7 +3316,7 @@ def main_open_sale(self) -> None: system.sale_id = None system.sale_status = 0 # Т.е. новая продажа system.sale_tickets = None - sale.exec_() + sale.exec() def main_get_statistic(self) -> None: """ @@ -3556,7 +3556,17 @@ class Payment: if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) app.setStyle("Fusion") + + # Загрузка и применение стилей + qss_path = Path(__file__).parent / "files" / "style.qss" + try: + with open(qss_path, "r", encoding="utf-8") as f: + app.setStyleSheet(f.read()) + except Exception as e: + logger.warning(f"Не удалось загрузить файл стилей: {e}") + auth = AuthForm() auth.show() auth.ui.label_9.setText(system.database) - sys.exit(app.exec()) + exit_code = app.exec() + sys.exit(exit_code)