import sys import os from PyQt6 import QtGui, QtWidgets from PyQt6 import uic from PyQt6.QtCore import Qt from PyQt6.QtGui import QFontDatabase, QFont from PyQt6.QtWidgets import QApplication, QMainWindow # Compile resources.qrc into resources_rc.py # rcc -g python resources.qrc -o resources_rc.py import resources # This is generated from the .qrc file # À placer tout en haut, avant les imports PyQt6 si possible if sys.platform.startswith('linux'): os.environ["QT_QPA_PLATFORM"] = "xcb" def load_custom_font(): # Load font from Qt resource font_id = QFontDatabase.addApplicationFont(":/assets/Avocado-Cake-Demo.otf") if font_id == -1: raise RuntimeError("Failed to load font from resources.") # Get the family name of the loaded font font_families = QFontDatabase.applicationFontFamilies(font_id) if not font_families: raise RuntimeError("No font families found in the loaded font.") return font_families[0] class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Remove the title bar and window frame self.setWindowFlags(Qt.WindowType.FramelessWindowHint |Qt.WindowType.Window) # Optional: Make background transparent (if you want rounded corners, etc.) self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) # Track mouse position for dragging self._drag_pos = None # Load font family from resource font_family = load_custom_font() uic.loadUi("mainwindow.ui", self) # Adjust UI self.maintitle_label.setFont(QFont(font_family, 38)) self.subtitle_label.setStyleSheet("color: rgb(163, 177, 198)") self.staff_btn.hide() self.spacer_substitution.hide() # Find the button by its objectName in Qt Designer # Example: objectName = "close_btn" self.close_btn.clicked.connect(self.close_link) self.minimize_btn.clicked.connect(self.minimize_link) def close_link(self): sys.exit(app.exec()) def minimize_link(self): # Minimize the application self.setWindowState(Qt.WindowState.WindowMinimized) # Mouse press event to start dragging def mousePressEvent(self, event): if event.button() == Qt.MouseButton.LeftButton: self._drag_pos = event.globalPosition().toPoint() - self.frameGeometry().topLeft() event.accept() # Mouse move event to drag window def mouseMoveEvent(self, event): if event.buttons() == Qt.MouseButton.LeftButton and self._drag_pos is not None: self.move(event.globalPosition().toPoint() - self._drag_pos) event.accept() # Mouse release event to stop dragging def mouseReleaseEvent(self, event): self._drag_pos = None event.accept() if __name__ == "__main__": app = QApplication(sys.argv) with open('styles.qss', 'r') as f: style = f.read() # Set the stylesheet of the application app.setStyleSheet(style) # Load and set the global font custom_font = QFont(load_custom_font(), 16) if custom_font: app.setFont(custom_font) window = MainWindow() window.show() sys.exit(app.exec())