commit 0ce305d76c6e6cc007bb98eeb940404bad41ab53 Author: Xarkam Date: Mon Mar 2 17:39:26 2026 +0100 first commit diff --git a/frameless.py b/frameless.py new file mode 100644 index 0000000..bf0d497 --- /dev/null +++ b/frameless.py @@ -0,0 +1,48 @@ +import sys +import os +from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget +from PyQt6.QtCore import Qt, QPoint + +# À placer tout en haut, avant les imports PyQt6 si possible +os.environ["QT_QPA_PLATFORM"] = "xcb" + +class FenetreSansTitre(QMainWindow): + def __init__(self): + super().__init__() + + self.setWindowFlags(Qt.WindowType.FramelessWindowHint) + self.resize(400, 300) + + # IMPORTANT : On active le suivi de souris + self.setMouseTracking(True) + + layout = QVBoxLayout() + btn_quitter = QPushButton("Quitter") + btn_quitter.clicked.connect(self.close) + layout.addWidget(btn_quitter) + + container = QWidget() + container.setLayout(layout) + self.setCentralWidget(container) + + self._drag_pos = None + + def mousePressEvent(self, event): + if event.button() == Qt.MouseButton.LeftButton: + # On enregistre la position du clic RELATIVE au coin haut-gauche de la fenêtre + self._drag_pos = event.position().toPoint() + + def mouseMoveEvent(self, event): + if self._drag_pos is not None: + # On déplace la fenêtre vers la position globale du curseur + # MOINS le décalage initial (offset) pour éviter que le curseur ne saute au centre + self.move(event.globalPosition().toPoint() - self._drag_pos) + + def mouseReleaseEvent(self, event): + self._drag_pos = None + +if __name__ == "__main__": + app = QApplication(sys.argv) + fenetre = FenetreSansTitre() + fenetre.show() + sys.exit(app.exec()) \ No newline at end of file diff --git a/frameless_for_MsWindow.py b/frameless_for_MsWindow.py new file mode 100644 index 0000000..3d8503b --- /dev/null +++ b/frameless_for_MsWindow.py @@ -0,0 +1,53 @@ +import sys +import os +from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget +from PyQt6.QtCore import Qt, QPoint + +# À placer tout en haut, avant les imports PyQt6 si possible +os.environ["QT_QPA_PLATFORM"] = "xcb" + +class FenetreSansTitre(QMainWindow): + def __init__(self): + super().__init__() + + # 1. Retirer la barre de titre + self.setWindowFlags(Qt.WindowType.FramelessWindowHint) + self.resize(400, 300) + + # Interface simple + layout = QVBoxLayout() + btn_quitter = QPushButton("Fermer la fenêtre") + btn_quitter.clicked.connect(self.close) + layout.addWidget(btn_quitter) + + container = QWidget() + container.setLayout(layout) + self.setCentralWidget(container) + + # Variable pour stocker la position du clic + self.old_pos = None + + # --- Logique de déplacement --- + + def mousePressEvent(self, event): + if event.button() == Qt.MouseButton.LeftButton: + # On sauvegarde la position relative du curseur dans la fenêtre + self.old_pos = event.globalPosition().toPoint() + + def mouseMoveEvent(self, event): + if self.old_pos is not None: + # Calcul de la distance parcourue + delta = QPoint(event.globalPosition().toPoint() - self.old_pos) + # Déplacement de la fenêtre + self.move(self.x() + delta.x(), self.y() + delta.y()) + # Mise à jour de la position de référence + self.old_pos = event.globalPosition().toPoint() + + def mouseReleaseEvent(self, event): + self.old_pos = None + +if __name__ == "__main__": + app = QApplication(sys.argv) + fenetre = FenetreSansTitre() + fenetre.show() + sys.exit(app.exec()) \ No newline at end of file diff --git a/mainwindow.py b/mainwindow.py new file mode 100644 index 0000000..3b304a3 --- /dev/null +++ b/mainwindow.py @@ -0,0 +1,60 @@ +import sys +import os +from PyQt6 import QtCore, QtGui, QtWidgets +from PyQt6 import uic +from PyQt6.QtCore import Qt + +# À placer tout en haut, avant les imports PyQt6 si possible +os.environ["QT_QPA_PLATFORM"] = "xcb" + +class MainWindow(QtWidgets.QMainWindow): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + # Remove the title bar and window frame + self.setWindowFlags(Qt.WindowType.FramelessWindowHint) + + # 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 + + uic.loadUi("mainwindow.ui", self) + + # 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() + + +app = QtWidgets.QApplication(sys.argv) + +window = MainWindow() +window.show() +app.exec() \ No newline at end of file diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..9322ea6 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,277 @@ + + + MainWindow + + + Qt::WindowModality::ApplicationModal + + + + 0 + 0 + 1199 + 703 + + + + + 0 + 0 + + + + + 1199 + 703 + + + + + 1199 + 703 + + + + Qt::ContextMenuPolicy::NoContextMenu + + + MainWindow + + + + + 1199 + 703 + + + + + 1199 + 703 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 1199 + 40 + + + + + 1199 + 40 + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Orientation::Horizontal + + + + 1006 + 20 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + #minimize_btn { + font: 700 11pt ; +} + + + _ + + + + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Fixed + + + + 20 + 20 + + + + + + + + + 32 + 32 + + + + + + + + + + + 32 + 32 + + + + + + + + + + + + 1199 + 0 + + + + + 1199 + 16777215 + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 350 + 660 + + + + + 350 + 660 + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + + + 0 + 0 + + + + + 0 + 673 + + + + + 16777215 + 673 + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + + + + + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f071fe7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +PyQt6==6.10.2 +PyQt6-Qt6==6.10.2 +PyQt6_sip==13.11.0