### Install PyQt-Frameless-Window from source Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/README.md This demonstrates how to install the PyQt-Frameless-Window library by cloning the repository and running the setup script. This method is useful for development or when you need the latest unreleased changes. ```shell git clone https://github.com/zhiyiYo/PyQt-Frameless-Window.git python setup.py install ``` -------------------------------- ### Installation Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/README.md Instructions on how to install the PyQt-Frameless-Window library using pip or by cloning the repository. ```APIDOC ## Installation To install the PyQt-Frameless-Window library, you can use pip: ```shell pip install PyQt5-Frameless-Window ``` Alternatively, you can clone the repository and install it locally: ```shell git clone https://github.com/zhiyiYo/PyQt-Frameless-Window.git python setup.py install ``` ``` -------------------------------- ### Basic Frameless Window Implementation in Python Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/README.md A minimal example demonstrating how to create a basic frameless window using PyQt5 and the PyQt-Frameless-Window library. It shows the necessary imports and class inheritance to get a functional frameless window. ```python import sys from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("PyQt-Frameless-Window") self.titleBar.raise_() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Basic Usage Example Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/README.md A minimal Python example demonstrating how to use the FramelessWindow class to create a basic frameless window. ```APIDOC ## Basic Usage To use the frameless window, you need to inherit from `FramelessWindow` or `FramelessMainWindow`. ### Minimal Example ```python import sys from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("PyQt-Frameless-Window") self.titleBar.raise_() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` For more complex examples, refer to the `demo.py` and `main_window.py` files in the repository. ``` -------------------------------- ### Implement Minimal Frameless Window Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/usage.md Demonstrates the basic setup required to create a frameless window by inheriting from FramelessWindow. It initializes the application and displays the window. ```python import sys from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("PyQt-Frameless-Window") self.titleBar.raise_() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Install PyQt5-Frameless-Window Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/quick-start.md Installs the PyQt5 version of the frameless window library using pip. This is a prerequisite for using frameless windows with PyQt5. ```shell pip install PyQt5-Frameless-Window ``` -------------------------------- ### Minimal Frameless Window Example Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/usage.md Demonstrates the basic implementation of a frameless window by inheriting from FramelessWindow. ```APIDOC ## Minimal Frameless Window ### Description This example shows how to create a basic frameless window by inheriting from the `FramelessWindow` class. ### Method N/A (This is a usage example, not an API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```python import sys from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("PyQt-Frameless-Window") self.titleBar.raise_() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` ### Response N/A ``` -------------------------------- ### Install PyQt6-Frameless-Window Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/quick-start.md Installs the PyQt6 version of the frameless window library using pip. This is required for applications using PyQt6. ```shell pip install PyQt6-Frameless-Window ``` -------------------------------- ### Install PySide6-Frameless-Window Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/quick-start.md Installs the PySide6 version of the frameless window library using pip. This is the command for projects using PySide6. ```shell pip install PySide6-Frameless-Window ``` -------------------------------- ### Create an Acrylic/Mica Window with PyQt Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt This example demonstrates creating a frameless window with acrylic or mica background effects using `AcrylicWindow`. It leverages platform-specific APIs to achieve blur effects on Windows (Aero, acrylic, mica) and native blur on macOS. Customization options for effect color and dark mode are commented out. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout from qframelesswindow import AcrylicWindow class Window(AcrylicWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Acrylic Window") layout = QVBoxLayout(self) layout.setContentsMargins(10, 40, 10, 10) label = QLabel("Transparent Acrylic Background") label.setStyleSheet("color: black; font-size: 16px;") layout.addWidget(label) self.titleBar.raise_() # Customize acrylic effect color (RGBA in hex: RRGGBBAA) # self.windowEffect.setAcrylicEffect(self.winId(), "106EBE99") # Enable mica effect on Windows 11 (instead of acrylic) # self.windowEffect.setMicaEffect(self.winId(), isDarkMode=False, isAlt=False) if __name__ == '__main__': QApplication.setHighDpiScaleFactorRoundingPolicy( Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Create Frameless Main Window with Menu and Status Bars Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Illustrates how to create a frameless main window using FramelessMainWindow, which supports menu bars, status bars, and central widgets. This example shows integrating a QMenuBar into the custom title bar and setting a QStatusBar and QTextEdit as the central widget. It also includes an example of a frameless dialog. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( QApplication, QLabel, QMenuBar, QMenu, QStatusBar, QTextEdit, QHBoxLayout ) from qframelesswindow import FramelessMainWindow, FramelessDialog class MainWindow(FramelessMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Frameless Main Window") # Add menu bar to title bar menuBar = QMenuBar(self.titleBar) menu = QMenu('File(&F)', self) menu.addAction('Open') menu.addAction('Save') menuBar.addMenu(menu) menuBar.addAction('Edit(&E)') menuBar.addAction('Help(&H)', self.showHelpDialog) # Insert menu bar into title bar layout self.titleBar.layout().insertWidget(0, menuBar, 0, Qt.AlignLeft) self.titleBar.layout().insertStretch(1, 1) self.setMenuWidget(self.titleBar) # Add status bar statusBar = QStatusBar(self) statusBar.addWidget(QLabel('Ready')) self.setStatusBar(statusBar) # Set central widget self.textEdit = QTextEdit() self.setCentralWidget(self.textEdit) self.setStyleSheet( """ QMenuBar{background: #F0F0F0; padding: 5px 0} QTextEdit{border: none; font-size: 15px} """ ) def showHelpDialog(self): dialog = FramelessDialog(self) dialog.setLayout(QHBoxLayout()) dialog.layout().addWidget(QLabel('Frameless Dialog'), 0, Qt.AlignCenter) dialog.titleBar.raise_() dialog.resize(300, 200) dialog.setResizeEnabled(False) # Disable dialog resizing dialog.exec() if __name__ == '__main__': QApplication.setHighDpiScaleFactorRoundingPolicy( Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) app = QApplication(sys.argv) app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings) window = MainWindow() window.show() app.exec() ``` -------------------------------- ### Install PySide2-Frameless-Window Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/quick-start.md Installs the PySide2 version of the frameless window library using pip. Use this command if your project utilizes PySide2. ```shell pip install PySide2-Frameless-Window ``` -------------------------------- ### PyQt Frameless Window Setup with Qt Designer Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/usage.md This Python code sets up a frameless PyQt window using multiple inheritance. It integrates a UI generated by Qt Designer, ensuring a 32px margin for the title bar. The `setupUi` method configures widgets and layouts, while the `Window` class inherits from `FramelessWindow` and the generated `Ui_Form` to create the application window. ```Python class Ui_Form(object): def setupUi(self, Form): Form.resize(400, 423) self.verticalLayout_2 = QVBoxLayout(Form) self.verticalLayout_2.setContentsMargins(-1, 32, -1, -1) self.frame_2 = QFrame(Form) self.verticalLayout = QVBoxLayout(self.frame_2) self.horizontalLayout = QHBoxLayout() self.pushButton = QPushButton(self.frame_2) self.horizontalLayout.addWidget(self.pushButton) self.lineEdit = QLineEdit(self.frame_2) self.horizontalLayout.addWidget(self.lineEdit) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout_2 = QHBoxLayout() self.pushButton_2 = QPushButton(self.frame_2) self.horizontalLayout_2.addWidget(self.pushButton_2) self.lineEdit_2 = QLineEdit(self.frame_2) self.horizontalLayout_2.addWidget(self.lineEdit_2) self.verticalLayout.addLayout(self.horizontalLayout_2) self.verticalLayout_2.addWidget(self.frame_2) self.frame = QFrame(Form) self.horizontalLayout_3 = QHBoxLayout(self.frame) self.tableView = QTableView(self.frame) self.horizontalLayout_3.addWidget(self.tableView) self.verticalLayout_2.addWidget(self.frame) self.retranslateUi(Form) def retranslateUi(self, Form): _translate = QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.pushButton.setText(_translate("Form", "选择文件")) self.pushButton_2.setText(_translate("Form", "创建路径")) class Window(FramelessWindow, Ui_Form): def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) ``` -------------------------------- ### Create Basic Frameless Window with PyQt5 Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Demonstrates how to create a basic frameless window using the FramelessWindow class. This includes setting window properties, adding content, and ensuring the title bar remains on top. It also shows how to enable high DPI scaling for the application. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("PyQt-Frameless-Window") # Add content to the window layout = QVBoxLayout(self) layout.setContentsMargins(10, 40, 10, 10) # Leave space for title bar label = QLabel("Hello, Frameless Window!") layout.addWidget(label) # Ensure title bar stays on top self.titleBar.raise_() if __name__ == '__main__': # Enable high DPI scaling QApplication.setHighDpiScaleFactorRoundingPolicy( Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Notes and Troubleshooting Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/README.md Important notes regarding custom title bars, known issues like acrylic blur performance, enabling snap layouts, and troubleshooting common import errors. ```APIDOC ## Notes 1. **Custom Title Bar**: `FramelessWindow` provides a default title bar. You can override it as shown in `demo.py` if needed. 2. **Acrylic Blur Performance**: Moving acrylic windows on Win10 might cause performance issues. Consider disabling acrylic effects during movement. 3. **Snap Layout**: Snap layout is not enabled by default. See issue [#56](https://github.com/zhiyiYo/PyQt-Frameless-Window/issues/56) for enabling instructions. 4. **`ImportError: DLL load failed` on Windows**: This can often be fixed by following solutions provided on [Stack Overflow](https://stackoverflow.com/questions/58612306/how-to-fix-importerror-dll-load-failed-while-importing-win32api/72488468#72488468) or the author's [blog](https://www.cnblogs.com/zhiyiYo/p/16340429.html). 5. **PySide/PyQt6 Compatibility**: For PySide2, PySide6, or PyQt6, use the respective branches available in the repository. ``` -------------------------------- ### Requirements Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/README.md Lists the platform-specific requirements for PyQt-Frameless-Window. ```APIDOC ## Requirements | Platform | Requirement | | :------: | :---------: | | Win32 | pywin32 | | Linux | xcffib | | MacOS | pyobjc | ``` -------------------------------- ### Implement Standard Title Bar with Icon Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/usage.md Demonstrates replacing the default title bar with StandardTitleBar to support window icons and titles. ```python from qframelesswindow import FramelessWindow, StandardTitleBar class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) # replace the default title bar with StandardTitleBar self.setTitleBar(StandardTitleBar(self)) self.setWindowIcon(QIcon("screenshot/logo.png")) self.setWindowTitle("PyQt-Frameless-Window") # don't forget to put the title bar at the top self.titleBar.raise_() ``` -------------------------------- ### Implement Acrylic Window Effect Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/window-effect.md Demonstrates how to subclass AcrylicWindow to create a window with a blur effect. It includes placeholders for customizing the acrylic color and enabling the Mica effect on Windows 11. ```python from qframelesswindow import AcrylicWindow class Window(AcrylicWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Acrylic Window") self.titleBar.raise_() ``` -------------------------------- ### Create a Frameless Dialog with PyQt Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt This snippet shows how to create and display a frameless dialog using `FramelessDialog` from the `qframelesswindow` library. It inherits from `QDialog` and allows for custom content and behavior, such as disabling resizing and handling close events. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout, QPushButton from qframelesswindow import FramelessWindow, FramelessDialog class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Main Window") layout = QVBoxLayout(self) layout.setContentsMargins(10, 40, 10, 10) button = QPushButton("Open Dialog") button.clicked.connect(self.openDialog) layout.addWidget(button) self.titleBar.raise_() def openDialog(self): dialog = FramelessDialog(self) layout = QVBoxLayout(dialog) layout.setContentsMargins(10, 40, 10, 10) layout.addWidget(QLabel("This is a frameless dialog")) closeBtn = QPushButton("Close") closeBtn.clicked.connect(dialog.accept) layout.addWidget(closeBtn) dialog.titleBar.raise_() dialog.resize(250, 150) dialog.setResizeEnabled(False) dialog.exec() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Enable Snap Layout in PyQt-Frameless-Window (Windows) Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/snap-layout.md This code snippet demonstrates how to modify the nativeEvent method in PyQt-Frameless-Window to enable the snap layout feature on Windows. It handles WM_NCHITTEST messages to correctly identify interactions with the maximize button and other window borders. Dependencies include win32con, QCursor, QMouseEvent, QApplication, and TitleBarButtonState. ```Python from ..titlebar.title_bar_buttons import TitleBarButtonState def nativeEvent(self, eventType, message): """ Handle the Windows message """ msg = MSG.from_address(message.__int__()) if not msg.hWnd: return super().nativeEvent(eventType, message) if msg.message == win32con.WM_NCHITTEST and self._isResizeEnabled: pos = QCursor.pos() xPos = pos.x() - self.x() yPos = pos.y() - self.y() w, h = self.width(), self.height() lx = xPos < self.BORDER_WIDTH rx = xPos > w - self.BORDER_WIDTH ty = yPos < self.BORDER_WIDTH by = yPos > h - self.BORDER_WIDTH if lx and ty: return True, win32con.HTTOPLEFT elif rx and by: return True, win32con.HTBOTTOMRIGHT elif rx and ty: return True, win32con.HTTOPRIGHT elif lx and by: return True, win32con.HTBOTTOMLEFT elif ty: return True, win32con.HTTOP elif by: return True, win32con.HTBOTTOM elif lx: return True, win32con.HTLEFT elif rx: return True, win32con.HTRIGHT #--------------------------------------- ADDED CODE --------------------------------------# elif self.titleBar.childAt(pos-self.geometry().topLeft()) is self.titleBar.maxBtn: self.titleBar.maxBtn.setState(TitleBarButtonState.HOVER) return True, win32con.HTMAXBUTTON elif msg.message in [0x2A2, win32con.WM_MOUSELEAVE]: self.titleBar.maxBtn.setState(TitleBarButtonState.NORMAL) elif msg.message in [win32con.WM_NCLBUTTONDOWN, win32con.WM_NCLBUTTONDBLCLK]: if self.titleBar.childAt(QCursor.pos()-self.geometry().topLeft()) is self.titleBar.maxBtn: QApplication.sendEvent(self.titleBar.maxBtn, QMouseEvent( QEvent.MouseButtonPress, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)) return True, 0 elif msg.message in [win32con.WM_NCLBUTTONUP, win32con.WM_NCRBUTTONUP]: if self.titleBar.childAt(QCursor.pos()-self.geometry().topLeft()) is self.titleBar.maxBtn: QApplication.sendEvent(self.titleBar.maxBtn, QMouseEvent( QEvent.MouseButtonRelease, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)) #------------------------------------------------------------------------------------------# elif msg.message == win32con.WM_NCCALCSIZE: if msg.wParam: rect = cast(msg.lParam, LPNCCALCSIZE_PARAMS).contents.rgrc[0] else: rect = cast(msg.lParam, LPRECT).contents isMax = win_utils.isMaximized(msg.hWnd) isFull = win_utils.isFullScreen(msg.hWnd) # adjust the size of client rect if isMax and not isFull: thickness = win_utils.getResizeBorderThickness(msg.hWnd) rect.top += thickness rect.left += thickness rect.right -= thickness rect.bottom -= thickness # handle the situation that an auto-hide taskbar is enabled if (isMax or isFull) and Taskbar.isAutoHide(): position = Taskbar.getPosition(msg.hWnd) if position == Taskbar.LEFT: rect.top += Taskbar.AUTO_HIDE_THICKNESS elif position == Taskbar.BOTTOM: rect.bottom -= Taskbar.AUTO_HIDE_THICKNESS elif position == Taskbar.LEFT: rect.left += Taskbar.AUTO_HIDE_THICKNESS elif position == Taskbar.RIGHT: rect.right -= Taskbar.AUTO_HIDE_THICKNESS result = 0 if not msg.wParam else win32con.WVR_REDRAW return True, result return super().nativeEvent(eventType, message) ``` -------------------------------- ### Class: FramelessMainWindow Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt A specialized class for creating full-featured main windows that support QMenuBar, QStatusBar, and central widgets while maintaining a frameless aesthetic. ```APIDOC ## Class: FramelessMainWindow ### Description Extends `QMainWindow` to provide a frameless experience. It allows for the integration of standard PyQt main window components like menus and status bars into the custom title bar area. ### Usage Inherit from `qframelesswindow.FramelessMainWindow` to build complex desktop applications with modern styling. ### Example ```python from qframelesswindow import FramelessMainWindow class MyMainWindow(FramelessMainWindow): def __init__(self): super().__init__() self.setCentralWidget(my_widget) self.setStatusBar(my_status_bar) ``` ``` -------------------------------- ### AcrylicWindow Class and Effects Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/window-effect.md Methods to initialize an acrylic window and toggle blur effects dynamically. ```APIDOC ## AcrylicWindow Class ### Description The AcrylicWindow class provides a base window with built-in acrylic blur effects. It allows for customization of window transparency and background effects. ### Methods - **setAcrylicEffect(winId, color)**: Applies the acrylic blur effect to the specified window ID. - **setMicaEffect(winId, enable)**: Enables or disables the Mica effect (Windows 11). - **addShadowEffect(winId)**: Adds a drop shadow to the window. - **removeBackgroundEffect(winId)**: Removes any applied background blur effects. ### Request Example ```python from qframelesswindow import AcrylicWindow class MyWindow(AcrylicWindow): def __init__(self): super().__init__() self.windowEffect.setAcrylicEffect(self.winId(), "106EBE99") ``` ### Implementation Note For Windows 10 compatibility, it is recommended to toggle the background style between transparent and solid colors when resizing to prevent UI lag. ``` -------------------------------- ### Control Window Resizing and Stay on Top with PyQt Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Demonstrates how to enable/disable window resizing and toggle the always-on-top behavior for a frameless PyQt window. It uses `setResizeEnabled` and `toggleStayOnTop` methods from the qframelesswindow library. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QVBoxLayout, QPushButton from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Window Controls Demo") layout = QVBoxLayout(self) layout.setContentsMargins(10, 40, 10, 10) # Toggle resize capability self.resizeBtn = QPushButton("Disable Resize") self.resizeBtn.clicked.connect(self.toggleResize) layout.addWidget(self.resizeBtn) # Toggle stay on top self.stayOnTopBtn = QPushButton("Enable Stay On Top") self.stayOnTopBtn.clicked.connect(self.toggleStayOnTop) layout.addWidget(self.stayOnTopBtn) self.titleBar.raise_() self._resizeEnabled = True def toggleResize(self): self._resizeEnabled = not self._resizeEnabled self.setResizeEnabled(self._resizeEnabled) self.resizeBtn.setText( "Disable Resize" if self._resizeEnabled else "Enable Resize" ) def toggleStayOnTop(self): # toggleStayOnTop() is a built-in method super().toggleStayOnTop() isOnTop = self.windowFlags() & Qt.WindowStaysOnTopHint self.stayOnTopBtn.setText( "Disable Stay On Top" if isOnTop else "Enable Stay On Top" ) if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### WindowEffect API Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Explains how to use the `windowEffect` object to add visual effects like shadows, blur, and animations to frameless windows. ```APIDOC ## WindowEffect API The `windowEffect` object provides methods to add visual effects to the window including shadows, blur effects, and window animations. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QColor from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Window Effects Demo") self.titleBar.raise_() # Window shadow effect (enabled by default on Windows) self.windowEffect.addShadowEffect(self.winId()) # Remove shadow effect # self.windowEffect.removeShadowEffect(self.winId()) # Enable window minimize/maximize animation self.windowEffect.addWindowAnimation(self.winId()) # Acrylic blur effect (Windows 10+, requires transparent background) # self.windowEffect.setAcrylicEffect(self.winId(), "F2F2F299") # Mica effect (Windows 11 only) # self.windowEffect.setMicaEffect(self.winId(), isDarkMode=False, isAlt=False) # Aero blur effect (Windows 7+) # self.windowEffect.setAeroEffect(self.winId()) # Remove background blur effect # self.windowEffect.removeBackgroundEffect(self.winId()) # Disable maximize button # self.windowEffect.disableMaximizeButton(self.winId()) # Set window border color (Windows 11 only) # self.windowEffect.setBorderAccentColor(self.winId(), QColor(0, 120, 212)) if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` ``` -------------------------------- ### Customize Title Bar Styling Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/usage.md Shows how to subclass TitleBar to customize button colors and styles using both programmatic methods and QSS stylesheets. ```python from qframelesswindow import FramelessWindow, TitleBar class CustomTitleBar(TitleBar): """ Custom title bar """ def __init__(self, parent): super().__init__(parent) # customize the style of title bar button self.minBtn.setHoverColor(Qt.white) self.minBtn.setHoverBackgroundColor(QColor(0, 100, 182)) self.minBtn.setPressedColor(Qt.white) self.minBtn.setPressedBackgroundColor(QColor(54, 57, 65)) # use qss to customize title bar button self.maxBtn.setStyleSheet(""" TitleBarButton { qproperty-normalColor: black; qproperty-normalBackgroundColor: transparent; qproperty-hoverColor: white; qproperty-hoverBackgroundColor: rgb(0, 100, 182); qproperty-pressedColor: white; qproperty-pressedBackgroundColor: rgb(54, 57, 65); } """) class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) # change the default title self.setTitleBar(CustomTitleBar(self)) ``` -------------------------------- ### Implement Screen Capture Protection with PyQt Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt This snippet shows how to use the `ScreenCaptureFilter` from `qframelesswindow.utils` to prevent window content from being captured in screenshots or recordings. The window content will appear black when captured. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout from qframelesswindow import FramelessWindow from qframelesswindow.utils import ScreenCaptureFilter class SecureWindow(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Screen Capture Protected Window") layout = QVBoxLayout(self) layout.setContentsMargins(10, 40, 10, 10) label = QLabel("This content is protected from screen capture") layout.addWidget(label) # Install screen capture filter to protect window content self.installEventFilter(ScreenCaptureFilter(self)) self.titleBar.raise_() if __name__ == "__main__": QApplication.setHighDpiScaleFactorRoundingPolicy( Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) app = QApplication(sys.argv) demo = SecureWindow() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Custom TitleBar with Styled Buttons Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Demonstrates how to create a custom title bar by inheriting from StandardTitleBar and customizing button appearances programmatically or using QSS. ```APIDOC ## Custom TitleBar with Styled Buttons Create a custom title bar by inheriting from `TitleBar` or `StandardTitleBar`. Customize button colors programmatically or via Qt stylesheets (QSS). ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QColor, QIcon from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow, StandardTitleBar class CustomTitleBar(StandardTitleBar): """Custom title bar with styled buttons""" def __init__(self, parent): super().__init__(parent) # Programmatically customize minimize button colors self.minBtn.setNormalColor(QColor(0, 0, 0)) # Icon color in normal state self.minBtn.setHoverColor(Qt.white) # Icon color on hover self.minBtn.setHoverBackgroundColor(QColor(0, 100, 182)) # Background on hover self.minBtn.setPressedColor(Qt.white) # Icon color when pressed self.minBtn.setPressedBackgroundColor(QColor(54, 57, 65)) # Background when pressed # Use QSS to customize maximize button self.maxBtn.setStyleSheet(""" TitleBarButton { qproperty-normalColor: black; qproperty-normalBackgroundColor: transparent; qproperty-hoverColor: white; qproperty-hoverBackgroundColor: rgb(0, 100, 182); qproperty-pressedColor: white; qproperty-pressedBackgroundColor: rgb(54, 57, 65); } """) class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setTitleBar(CustomTitleBar(self)) self.setWindowIcon(QIcon("icon.png")) self.setWindowTitle("Custom Title Bar Demo") self.setStyleSheet("background: white") self.titleBar.raise_() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` ``` -------------------------------- ### Applying Window Effects in PyQt Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Utilizes the windowEffect API to add visual effects like shadows, blur, and animations to frameless windows. This API is platform-dependent and offers options for acrylic blur, mica effect, aero blur, and border accent colors. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QColor from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Window Effects Demo") self.titleBar.raise_() # Window shadow effect (enabled by default on Windows) self.windowEffect.addShadowEffect(self.winId()) # Remove shadow effect # self.windowEffect.removeShadowEffect(self.winId()) # Enable window minimize/maximize animation self.windowEffect.addWindowAnimation(self.winId()) # Acrylic blur effect (Windows 10+, requires transparent background) # self.windowEffect.setAcrylicEffect(self.winId(), "F2F2F299") # Mica effect (Windows 11 only) # self.windowEffect.setMicaEffect(self.winId(), isDarkMode=False, isAlt=False) # Aero blur effect (Windows 7+) # self.windowEffect.setAeroEffect(self.winId()) # Remove background blur effect # self.windowEffect.removeBackgroundEffect(self.winId()) # Disable maximize button # self.windowEffect.disableMaximizeButton(self.winId()) # Set window border color (Windows 11 only) # self.windowEffect.setBorderAccentColor(self.winId(), QColor(0, 120, 212)) if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Custom Title Bar with Styled Buttons in PyQt Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Demonstrates how to create a custom title bar by inheriting from StandardTitleBar and customizing button appearance programmatically or via QSS. This allows for fine-grained control over button colors and backgrounds in different states. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QColor, QIcon from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow, StandardTitleBar class CustomTitleBar(StandardTitleBar): """Custom title bar with styled buttons""" def __init__(self, parent): super().__init__(parent) # Programmatically customize minimize button colors self.minBtn.setNormalColor(QColor(0, 0, 0)) # Icon color in normal state self.minBtn.setHoverColor(Qt.white) self.minBtn.setHoverBackgroundColor(QColor(0, 100, 182)) self.minBtn.setPressedColor(Qt.white) self.minBtn.setPressedBackgroundColor(QColor(54, 57, 65)) # Use QSS to customize maximize button self.maxBtn.setStyleSheet(""" TitleBarButton { qproperty-normalColor: black; qproperty-normalBackgroundColor: transparent; qproperty-hoverColor: white; qproperty-hoverBackgroundColor: rgb(0, 100, 182); qproperty-pressedColor: white; qproperty-pressedBackgroundColor: rgb(54, 57, 65); } """) class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setTitleBar(CustomTitleBar(self)) self.setWindowIcon(QIcon("icon.png")) self.setWindowTitle("Custom Title Bar Demo") self.setStyleSheet("background: white") self.titleBar.raise_() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Implement a Standard Title Bar with PyQt Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt This code snippet illustrates how to replace the default title bar of a frameless window with a `StandardTitleBar`. This custom title bar automatically displays the window's icon and title, which can be set using `setWindowIcon()` and `setWindowTitle()`. It also provides options for manually setting the icon and title. ```python import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow, StandardTitleBar class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) # Replace default title bar with StandardTitleBar self.setTitleBar(StandardTitleBar(self)) # Set window icon and title (automatically reflected in title bar) self.setWindowIcon(QIcon("icon.png")) self.setWindowTitle("My Application") # Manually set title bar icon and title (optional) # self.titleBar.setIcon("another_icon.png") # self.titleBar.setTitle("Custom Title") self.setStyleSheet("background: white") self.titleBar.raise_() if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Handle Windows Native Events for Frameless Window (Python) Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/snap-layout.md This Python code snippet handles Windows native messages (WM_NCHITTEST, WM_MOUSELEAVE, etc.) to enable custom behavior for frameless windows. It specifically manages interactions with a maximize button, including hover effects and click events, by simulating PyQt mouse events. Dependencies include PyQt and win32con. ```Python def nativeEvent(self, eventType, message): """ Handle the Windows message """ msg = MSG.from_address(message.__int__()) if not msg.hWnd: return super().nativeEvent(eventType, message) if msg.message == win32con.WM_NCHITTEST and self._isResizeEnabled: if self._isHoverMaxBtn(): self.titleBar.maxBtn.setState(TitleBarButtonState.HOVER) return True, win32con.HTMAXBUTTON elif msg.message in [0x2A2, win32con.WM_MOUSELEAVE]: self.titleBar.maxBtn.setState(TitleBarButtonState.NORMAL) elif msg.message in [win32con.WM_NCLBUTTONDOWN, win32con.WM_NCLBUTTONDBLCLK] and self._isHoverMaxBtn(): e = QMouseEvent(QEvent.MouseButtonPress, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.sendEvent(self.titleBar.maxBtn, e) return True, 0 elif msg.message in [win32con.WM_NCLBUTTONUP, win32con.WM_NCRBUTTONUP] and self._isHoverMaxBtn(): e = QMouseEvent(QEvent.MouseButtonRelease, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.sendEvent(self.titleBar.maxBtn, e) return super().nativeEvent(eventType, message) def _isHoverMaxBtn(self): pos = QCursor.pos() - self.geometry().topLeft() - self.titleBar.pos() return self.titleBar.childAt(pos) is self.titleBar.maxBtn ``` -------------------------------- ### Customizing the Title Bar Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/usage.md Illustrates how to customize the default title bar, including button styles and using a custom TitleBar class. ```APIDOC ## Customizing the Title Bar ### Description This section explains how to customize the default `TitleBar` provided by the library. You can change button colors and styles, or replace it with a `StandardTitleBar` for icon and title display. ### Method N/A (This is a usage example, not an API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example #### Customizing Button Styles ```python from qframelesswindow import FramelessWindow, TitleBar from PyQt5.QtGui import Qt, QColor class CustomTitleBar(TitleBar): """ Custom title bar """ def __init__(self, parent): super().__init__(parent) # customize the style of title bar button self.minBtn.setHoverColor(Qt.white) self.minBtn.setHoverBackgroundColor(QColor(0, 100, 182)) self.minBtn.setPressedColor(Qt.white) self.minBtn.setPressedBackgroundColor(QColor(54, 57, 65)) # use qss to customize title bar button self.maxBtn.setStyleSheet(""" TitleBarButton { qproperty-normalColor: black; qproperty-normalBackgroundColor: transparent; qproperty-hoverColor: white; qproperty-hoverBackgroundColor: rgb(0, 100, 182); qproperty-pressedColor: white; qproperty-pressedBackgroundColor: rgb(54, 57, 65); } """) class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) # change the default title self.setTitleBar(CustomTitleBar(self)) ``` #### Using StandardTitleBar with Icon and Title ```python from qframelesswindow import FramelessWindow, StandardTitleBar from PyQt5.QtGui import QIcon class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) # replace the default title bar with StandardTitleBar self.setTitleBar(StandardTitleBar(self)) self.setWindowIcon(QIcon("screenshot/logo.png")) self.setWindowTitle("PyQt-Frameless-Window") # don't forget to put the title bar at the top self.titleBar.raise_() ``` ### Response N/A ``` -------------------------------- ### Class: FramelessWindow Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt The base class for creating a simple frameless window. It provides a default title bar with window controls and handles basic window interactions. ```APIDOC ## Class: FramelessWindow ### Description Base class for creating frameless windows. Inherit from this to implement a window without the OS title bar, featuring built-in support for moving, resizing, and window controls. ### Usage Inherit from `qframelesswindow.FramelessWindow` and implement your custom UI within the `__init__` method. ### Example ```python from qframelesswindow import FramelessWindow class MyWindow(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("My Frameless App") ``` ``` -------------------------------- ### Configure macOS Native Title Bar Buttons Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Demonstrates how to display native macOS traffic light buttons within a frameless window. It uses the systemTitleBarRect method to define the placement area for these buttons. ```python import sys from PyQt5.QtCore import QRect, QSize, Qt from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow class Window(FramelessWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("macOS Native Buttons Demo") self.setStyleSheet("background: white") self.titleBar.raise_() if sys.platform == "darwin": self.setSystemTitleBarButtonVisible(True) self.titleBar.minBtn.hide() self.titleBar.maxBtn.hide() self.titleBar.closeBtn.hide() def systemTitleBarRect(self, size: QSize) -> QRect: return QRect(size.width() - 75, 0, 75, size.height()) if __name__ == "__main__": app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Inherit FramelessWindow to Rewrite nativeEvent (Python) Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/snap-layout.md This Python code snippet shows how to create a custom frameless window by inheriting from PyQt-Frameless-Window's FramelessWindow class and overriding the nativeEvent method. This approach allows for custom handling of Windows messages, such as those related to window resizing and maximizing, without altering the original library code. It includes necessary imports for PyQt5 and the frameless window functionality. ```Python import sys if sys.platform != "win32": from qframelesswindow import FramelessWindow else: from ctypes.wintypes import MSG import win32con from PyQt5.QtCore import QPoint, QEvent, Qt from PyQt5.QtGui import QCursor, QMouseEvent from PyQt5.QtWidgets import QApplication from qframelesswindow import FramelessWindow as Window from qframelesswindow.titlebar.title_bar_buttons import TitleBarButtonState class FramelessWindow(Window): """ Frameless window """ def nativeEvent(self, eventType, message): ``` -------------------------------- ### Toggle Acrylic Blur Effect Dynamically Source: https://context7.com/zhiyiyo/pyqt-frameless-window/llms.txt Shows how to toggle the acrylic blur effect on Windows platforms. This is useful for performance optimization during window movement or user-defined settings. ```python import sys from PyQt5.QtCore import Qt, QOperatingSystemVersion from PyQt5.QtWidgets import QApplication, QVBoxLayout, QPushButton from qframelesswindow import AcrylicWindow class Window(AcrylicWindow): def __init__(self, parent=None): super().__init__(parent=parent) self.setWindowTitle("Toggle Acrylic Demo") self._acrylicEnabled = True layout = QVBoxLayout(self) layout.setContentsMargins(10, 40, 10, 10) self.toggleBtn = QPushButton("Disable Acrylic") self.toggleBtn.clicked.connect(self.toggleAcrylic) layout.addWidget(self.toggleBtn) self.titleBar.raise_() def toggleAcrylic(self): self._acrylicEnabled = not self._acrylicEnabled self.setAcrylicEffectEnabled(self._acrylicEnabled) self.toggleBtn.setText("Disable Acrylic" if self._acrylicEnabled else "Enable Acrylic") def setAcrylicEffectEnabled(self, enable: bool): self.setStyleSheet(f"background:{'transparent' if enable else '#F2F2F2'}") if enable: self.windowEffect.setAcrylicEffect(self.winId(), "F2F2F299") if QOperatingSystemVersion.current() != QOperatingSystemVersion.Windows10: self.windowEffect.addShadowEffect(self.winId()) else: self.windowEffect.addShadowEffect(self.winId()) self.windowEffect.removeBackgroundEffect(self.winId()) if __name__ == '__main__': app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_()) ``` -------------------------------- ### Toggle Acrylic Effect Dynamically Source: https://github.com/zhiyiyo/pyqt-frameless-window/blob/master/docs/source/window-effect.md Provides a method to toggle the acrylic effect on and off. This is useful for mitigating performance issues during window resizing or movement on Windows 10 by switching between transparent and solid backgrounds. ```python def setAcrylicEffectEnabled(self, enable: bool): """ set acrylic effect enabled """ self.setStyleSheet(f"background:{'transparent' if enable else '#F2F2F2'}") if enable: self.windowEffect.setAcrylicEffect(self.winId(), "F2F2F299") if QOperatingSystemVersion.current() != QOperatingSystemVersion.Windows10: self.windowEffect.addShadowEffect(self.winId()) else: self.windowEffect.addShadowEffect(self.winId()) self.windowEffect.removeBackgroundEffect(self.winId()) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.