### Full pyqt-liquidglass window example Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/getting_started.rst A complete example demonstrating how to create a main window with a glass effect using pyqt-liquidglass and PySide6. It includes setting up the window, widgets, and applying the glass effect. ```python import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QVBoxLayout, QWidget import pyqt_liquidglass as glass class MainWindow(QMainWindow): def __init__(self) -> None: super().__init__() self.setWindowTitle("Glass Demo") self.resize(600, 400) central = QWidget() central.setStyleSheet("background: transparent;") layout = QVBoxLayout(central) layout.setContentsMargins(40, 60, 40, 40) label = QLabel("Hello, Liquid Glass!") label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setStyleSheet(""" font-size: 28px; font-weight: 600; color: white; background: transparent; """) layout.addWidget(label) self.setCentralWidget(central) def main() -> int: app = QApplication(sys.argv) window = MainWindow() glass.prepare_window_for_glass(window) window.show() glass.apply_glass_to_window(window) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Apply pyqt-liquidglass effect to a window Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/getting_started.rst Demonstrates the three-step process to apply a glass effect to a Qt window using pyqt-liquidglass. This involves preparing the window, showing it, and then applying the effect. ```python import pyqt_liquidglass as glass # 1. Prepare before showing glass.prepare_window_for_glass(window) # 2. Show the window window.show() # 3. Apply glass after showing glass.apply_glass_to_window(window) ``` -------------------------------- ### Install pyqt-liquidglass using uv Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/getting_started.rst Installs the pyqt-liquidglass library using the uv package manager. uv is a fast, modern Python package installer. ```bash uv add pyqt-liquidglass ``` -------------------------------- ### Demonstrate Custom GlassOptions Configurations Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/examples.rst Illustrates how to use custom `GlassOptions` to configure different glass effects side-by-side. This example shows how to apply distinct visual styles to multiple widgets. Dependencies include PySide6 and pyqt-liquidglass. ```python """Custom GlassOptions example.""" import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import ( QApplication, QHBoxLayout, QLabel, QMainWindow, QVBoxLayout, QWidget, ) import pyqt_liquidglass as glass class GlassPanel(QWidget): """A panel that will have glass applied to it.""" def __init__(self, title: str, parent: QWidget | None = None) -> None: super().__init__(parent) self.setStyleSheet("background: transparent;") layout = QVBoxLayout(self) layout.setContentsMargins(20, 20, 20, 20) label = QLabel(title) label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setStyleSheet(""" font-size: 16px; font-weight: 600; color: white; background: transparent; """) layout.addWidget(label) class MainWindow(QMainWindow): def __init__(self) -> None: super().__init__() self.setWindowTitle("Custom GlassOptions Example") central_widget = QWidget() self.setCentralWidget(central_widget) main_layout = QHBoxLayout(central_widget) main_layout.setContentsMargins(50, 50, 50, 50) main_layout.setSpacing(32) # Panel with default sidebar options panel1 = GlassPanel("Sidebar Style") glass.apply_glass_to_widget(panel1, options=glass.GlassOptions.sidebar()) # Panel with custom rounded corners panel2 = GlassPanel("Rounded Corners") glass.apply_glass_to_widget(panel2, options=glass.GlassOptions(corner_radius=24.0)) # Panel with a different corner radius and background blur panel3 = GlassPanel("Blur Effect") glass.apply_glass_to_widget(panel3, options=glass.GlassOptions(corner_radius=8.0, background_blur=10.0)) main_layout.addWidget(panel1) main_layout.addWidget(panel2) main_layout.addWidget(panel3) # Prepare window for glass effect (needed for blur to work on some platforms) glass.prepare_window_for_glass(self) def main() -> int: app = QApplication(sys.argv) window = MainWindow() window.resize(800, 400) window.show() return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Install pyqt-liquidglass using pip Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/getting_started.rst Installs the pyqt-liquidglass library using the pip package manager. This is the standard method for adding Python packages to your project. ```bash pip install pyqt-liquidglass ``` -------------------------------- ### Full Window Glass Effect with PySide6 Source: https://pyqt-liquidglass.readthedocs.io/en/latest/examples This example demonstrates how to apply a glass effect to an entire PySide6 window. It involves preparing the window for the glass effect before showing it and then applying the effect after the window is visible. The `pyqt_liquidglass` library is used for this purpose. ```python """Full window glass effect example.""" import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QVBoxLayout, QWidget import pyqt_liquidglass as glass class MainWindow(QMainWindow): def __init__(self) -> None: super().__init__() self.setWindowTitle("Window Glass") self.resize(600, 400) central = QWidget() central.setStyleSheet("background: transparent;") layout = QVBoxLayout(central) layout.setContentsMargins(40, 60, 40, 40) label = QLabel("Hello, Liquid Glass!") label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setStyleSheet(""" font-size: 28px; font-weight: 600; color: white; background: transparent; """) layout.addWidget(label) self.setCentralWidget(central) def main() -> int: app = QApplication(sys.argv) window = MainWindow() # Prepare window BEFORE showing glass.prepare_window_for_glass(window) window.show() # Apply glass AFTER showing glass.apply_glass_to_window(window) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Prepare and Show Window with LiquidGlass Effect Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/examples.rst Prepares a PyQt window for the LiquidGlass effect, displays it, and then applies the effect. It also repositions traffic lights with custom offsets. This function is essential for initializing the visual appearance of the application window. ```python import sys # Assuming 'glass' and 'app' are imported and initialized elsewhere # from PyQt5.QtWidgets import QApplication, QWidget # from liquidglass import LiquidGlass def main(): app = QApplication(sys.argv) window = QWidget() # Replace with your actual window type glass = LiquidGlass() # Prepare window for glass effect glass.prepare_window_for_glass(window) window.show() # Apply glass to window glass.apply_glass_to_window(window) # Reposition traffic lights with custom offset glass.setup_traffic_lights_inset(window, x_offset=20, y_offset=16) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Control macOS Traffic Lights Visibility and Position with PyQt LiquidGlass Source: https://pyqt-liquidglass.readthedocs.io/en/latest/examples This Python code demonstrates how to use the pyqt-liquidglass library to manage the macOS window traffic lights. It allows hiding, showing, and repositioning these buttons with custom offsets. The example requires PySide6 and pyqt-liquidglass. ```python """Traffic lights control example.""" import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import ( QApplication, QHBoxLayout, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget, ) import pyqt_liquidglass as glass class MainWindow(QMainWindow): def __init__(self) -> None: super().__init__() self.setWindowTitle("Traffic Lights Demo") self.resize(500, 300) self._lights_visible = True central = QWidget() central.setStyleSheet("background: transparent;") layout = QVBoxLayout(central) layout.setContentsMargins(40, 80, 40, 40) layout.setSpacing(20) title = QLabel("Traffic Lights Control") title.setAlignment(Qt.AlignmentFlag.AlignCenter) title.setStyleSheet(""" font-size: 22px; font-weight: 600; color: white; background: transparent; """) description = QLabel( "The traffic lights have been repositioned.\n" "Use the button below to hide or show them." ) description.setAlignment(Qt.AlignmentFlag.AlignCenter) description.setStyleSheet(""" font-size: 13px; color: rgba(255, 255, 255, 0.7); background: transparent; """) buttons_layout = QHBoxLayout() buttons_layout.setSpacing(12) self.toggle_button = QPushButton("Hide Traffic Lights") self.toggle_button.setStyleSheet(""" QPushButton { background: rgba(255, 255, 255, 0.15); border: none; border-radius: 8px; padding: 12px 24px; color: white; font-size: 13px; min-width: 160px; } QPushButton:hover { background: rgba(255, 255, 255, 0.25); } QPushButton:pressed { background: rgba(255, 255, 255, 0.1); } """) self.toggle_button.clicked.connect(self._toggle_traffic_lights) buttons_layout.addStretch() buttons_layout.addWidget(self.toggle_button) buttons_layout.addStretch() layout.addWidget(title) layout.addWidget(description) layout.addStretch() layout.addLayout(buttons_layout) self.setCentralWidget(central) def _toggle_traffic_lights(self) -> None: if self._lights_visible: glass.hide_traffic_lights(self) self.toggle_button.setText("Show Traffic Lights") else: glass.show_traffic_lights(self) self.toggle_button.setText("Hide Traffic Lights") self._lights_visible = not self._lights_visible def main() -> int: app = QApplication(sys.argv) window = MainWindow() glass.prepare_window_for_glass(window) window.show() # Apply glass to window glass.apply_glass_to_window(window) # Reposition traffic lights with custom offset glass.setup_traffic_lights_inset(window, x_offset=20, y_offset=16) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Apply Custom Glass Options to Widgets Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/examples.rst Demonstrates how to apply different glass background effects to individual widgets within a PyQt window. It shows how to customize corner radius and padding for a visually distinct appearance. Requires the pyqt_liquidglass library. ```python import sys from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout import pyqt_liquidglass as glass class GlassPanel(QWidget): def __init__(self, text="", parent=None): super().__init__(parent) self.setContentsMargins(0, 0, 0, 0) class MainWindow(QWidget): def __init__(self) -> None: super().__init__() self.setWindowTitle("Custom Glass Options") self.resize(800, 400) central = QWidget() central.setStyleSheet("background: transparent;") layout = QHBoxLayout(central) layout.setContentsMargins(20, 60, 20, 20) layout.setSpacing(20) self.panel_default = GlassPanel("Default\n(no radius)") self.panel_default.setFixedWidth(200) self.panel_rounded = GlassPanel("Rounded\n(radius: 16)") self.panel_rounded.setFixedWidth(200) self.panel_padded = GlassPanel("Padded\n(padding: 20)") self.panel_padded.setFixedWidth(200) layout.addWidget(self.panel_default) layout.addWidget(self.panel_rounded) layout.addWidget(self.panel_padded) self.setCentralWidget(central) def main() -> int: app = QApplication(sys.argv) window = MainWindow() glass.prepare_window_for_glass(window) window.show() # Apply window glass as background glass.apply_glass_to_window(window) # Apply different glass options to each panel glass.apply_glass_to_widget( window.panel_default, options=glass.GlassOptions(corner_radius=0.0, padding=(8, 8, 8, 8)), ) glass.apply_glass_to_widget( window.panel_rounded, options=glass.GlassOptions(corner_radius=16.0, padding=(8, 8, 8, 8)), ) glass.apply_glass_to_widget( window.panel_padded, options=glass.GlassOptions(corner_radius=12.0, padding=(20, 20, 20, 20)), ) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Install pyqt-liquidglass using pip or uv Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/index.rst Instructions for installing the pyqt-liquidglass library using package managers. Supports both pip and uv. Requires Python 3.12+ and macOS. ```bash pip install pyqt-liquidglass ``` ```bash uv add pyqt-liquidglass ``` -------------------------------- ### PyQt Custom GlassOptions with pyqt-liquidglass Source: https://pyqt-liquidglass.readthedocs.io/en/latest/examples This Python code demonstrates how to apply custom glass effects to PyQt widgets using the pyqt-liquidglass library. It defines a main window with several panels and applies different `GlassOptions` to each, controlling corner radius and padding. Dependencies include PySide6 and pyqt-liquidglass. ```python """Custom GlassOptions example.""" import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import ( QApplication, QHBoxLayout, QLabel, QMainWindow, QVBoxLayout, QWidget, ) import pyqt_liquidglass as glass class GlassPanel(QWidget): """A panel that will have glass applied to it.""" def __init__(self, title: str, parent: QWidget | None = None) -> None: super().__init__(parent) self.setStyleSheet("background: transparent;") layout = QVBoxLayout(self) layout.setContentsMargins(20, 20, 20, 20) label = QLabel(title) label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setStyleSheet(""" font-size: 16px; font-weight: 600; color: white; background: transparent; """) layout.addWidget(label) class MainWindow(QMainWindow): def __init__(self) -> None: super().__init__() self.setWindowTitle("Custom Glass Options") self.resize(800, 400) central = QWidget() central.setStyleSheet("background: transparent;") layout = QHBoxLayout(central) layout.setContentsMargins(20, 60, 20, 20) layout.setSpacing(20) self.panel_default = GlassPanel("Default\n(no radius)") self.panel_default.setFixedWidth(200) self.panel_rounded = GlassPanel("Rounded\n(radius: 16)") self.panel_rounded.setFixedWidth(200) self.panel_padded = GlassPanel("Padded\n(padding: 20)") self.panel_padded.setFixedWidth(200) layout.addWidget(self.panel_default) layout.addWidget(self.panel_rounded) layout.addWidget(self.panel_padded) self.setCentralWidget(central) def main() -> int: app = QApplication(sys.argv) window = MainWindow() glass.prepare_window_for_glass(window) window.show() # Apply window glass as background glass.apply_glass_to_window(window) # Apply different glass options to each panel glass.apply_glass_to_widget( window.panel_default, options=glass.GlassOptions(corner_radius=0.0, padding=(8, 8, 8, 8)), ) glass.apply_glass_to_widget( window.panel_rounded, options=glass.GlassOptions(corner_radius=16.0, padding=(8, 8, 8, 8)), ) glass.apply_glass_to_widget( window.panel_padded, options=glass.GlassOptions(corner_radius=12.0, padding=(20, 20, 20, 20)), ) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Manage macOS Traffic Lights with PyQt-Liquidglass (Python) Source: https://pyqt-liquidglass.readthedocs.io/en/latest/getting_started Provides functions to reposition, hide, or show the macOS window traffic light buttons (close, minimize, maximize) using pyqt-liquidglass. `setup_traffic_lights_inset` allows for custom positioning with offsets, while `hide_traffic_lights` and `show_traffic_lights` control their visibility. ```python glass.setup_traffic_lights_inset(window, x_offset=20, y_offset=12) glass.hide_traffic_lights(window) glass.show_traffic_lights(window) ``` -------------------------------- ### Manage macOS window traffic lights with pyqt-liquidglass Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/getting_started.rst Provides functions to reposition, hide, and show the macOS window traffic light buttons (close, minimize, maximize) using pyqt-liquidglass. ```python # Reposition traffic lights glass.setup_traffic_lights_inset(window, x_offset=20, y_offset=12) # Hide or show traffic lights glass.hide_traffic_lights(window) glass.show_traffic_lights(window) ``` -------------------------------- ### Sidebar Pattern with Glass Effect using PySide6 Source: https://pyqt-liquidglass.readthedocs.io/en/latest/examples This example implements a common macOS settings-style window with a glass sidebar and an opaque content area. It utilizes `pyqt_liquidglass` to apply a glass effect specifically to the sidebar widget, allowing for rounded corners and a distinct visual separation. The code defines separate widgets for the sidebar and content, then arranges them using a horizontal layout. ```python """Sidebar with glass effect example.""" import sys from PySide6.QtWidgets import ( QApplication, QHBoxLayout, QLabel, QListWidget, QListWidgetItem, QMainWindow, QVBoxLayout, QWidget, ) import pyqt_liquidglass as glass class Sidebar(QWidget): """Transparent sidebar widget for glass effect.""" def __init__(self, parent: QWidget | None = None) -> None: super().__init__(parent) self.setFixedWidth(250) self.setStyleSheet("background: transparent;") layout = QVBoxLayout(self) layout.setContentsMargins(9, 18, 9, 9) self.list_widget = QListWidget() self.list_widget.setStyleSheet(""" QListWidget { font-size: 13px; background: transparent; border: none; outline: none; } QListWidget::item { padding: 5px 2px; margin: 0px 9px; border-radius: 4px; } QListWidget::item:selected { background: rgba(255, 255, 255, 0.1); } """) self.list_widget.viewport().setStyleSheet("background: transparent;") for item_text in ["General", "Appearance", "Sound", "Network", "Privacy"]: self.list_widget.addItem(QListWidgetItem(item_text)) self.list_widget.setCurrentRow(0) layout.addWidget(self.list_widget) class Content(QWidget): """Opaque content area.""" def __init__(self, parent: QWidget | None = None) -> None: super().__init__(parent) self.setStyleSheet("background-color: #1e1e1e;") layout = QVBoxLayout(self) layout.setContentsMargins(20, 20, 20, 20) self.title = QLabel("General") self.title.setStyleSheet(""" font-size: 18px; font-weight: bold; color: white; background: transparent; """) self.description = QLabel("Configure general application settings.") self.description.setStyleSheet(""" font-size: 14px; color: #888888; background: transparent; """) layout.addWidget(self.title) layout.addSpacing(8) layout.addWidget(self.description) layout.addStretch() class MainWindow(QMainWindow): def __init__(self) -> None: super().__init__() self.setWindowTitle("Settings") self.resize(720, 600) central = QWidget() layout = QHBoxLayout(central) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.sidebar = Sidebar() self.content = Content() layout.addWidget(self.sidebar) layout.addWidget(self.content, 1) self.setCentralWidget(central) def main() -> int: app = QApplication(sys.argv) window = MainWindow() glass.prepare_window_for_glass(window) window.show() # Inset traffic lights to sit nicely on sidebar glass.setup_traffic_lights_inset(window, x_offset=18, y_offset=12) # Apply glass to sidebar with rounded corners glass.apply_glass_to_widget(window.sidebar, options=glass.GlassOptions.sidebar()) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Apply pyqt-liquidglass effect to a specific widget Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/getting_started.rst Shows how to apply a glass effect to an individual Qt widget, such as a sidebar. This is done after the main window has been displayed. ```python sidebar = QWidget() sidebar.setFixedWidth(250) sidebar.setStyleSheet("background: transparent;") # After window.show(): glass.apply_glass_to_widget(sidebar, options=glass.GlassOptions.sidebar()) ``` -------------------------------- ### Control macOS Window Traffic Lights Visibility Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/examples.rst Demonstrates how to hide and show the macOS window traffic light buttons (close, minimize, maximize) using the pyqt_liquidglass library. This allows for custom window controls or a cleaner interface. It includes a button to toggle the visibility. ```python import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import ( QApplication, QHBoxLayout, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget, ) import pyqt_liquidglass as glass class MainWindow(QMainWindow): def __init__(self) -> None: super().__init__() self.setWindowTitle("Traffic Lights Demo") self.resize(500, 300) self._lights_visible = True central = QWidget() central.setStyleSheet("background: transparent;") layout = QVBoxLayout(central) layout.setContentsMargins(40, 80, 40, 40) layout.setSpacing(20) title = QLabel("Traffic Lights Control") title.setAlignment(Qt.AlignmentFlag.AlignCenter) title.setStyleSheet(""" font-size: 22px; font-weight: 600; color: white; background: transparent; """) description = QLabel( "The traffic lights have been repositioned.\n" "Use the button below to hide or show them." ) description.setAlignment(Qt.AlignmentFlag.AlignCenter) description.setStyleSheet(""" font-size: 13px; color: rgba(255, 255, 255, 0.7); background: transparent; """) buttons_layout = QHBoxLayout() buttons_layout.setSpacing(12) self.toggle_button = QPushButton("Hide Traffic Lights") self.toggle_button.setStyleSheet(""" QPushButton { background: rgba(255, 255, 255, 0.15); border: none; border-radius: 8px; padding: 12px 24px; color: white; font-size: 13px; min-width: 160px; } QPushButton:hover { background: rgba(255, 255, 255, 0.25); } QPushButton:pressed { background: rgba(255, 255, 255, 0.1); } """) self.toggle_button.clicked.connect(self._toggle_traffic_lights) buttons_layout.addStretch() buttons_layout.addWidget(self.toggle_button) buttons_layout.addStretch() layout.addWidget(title) layout.addWidget(description) layout.addStretch() layout.addLayout(buttons_layout) self.setCentralWidget(central) def _toggle_traffic_lights(self) -> None: if self._lights_visible: glass.hide_traffic_lights(self) self.toggle_button.setText("Show Traffic Lights") else: glass.show_traffic_lights(self) self.toggle_button.setText("Hide Traffic Lights") self._lights_visible = not self._lights_visible def main() -> int: app = QApplication(sys.argv) window = MainWindow() return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Setup Traffic Lights Inset Source: https://pyqt-liquidglass.readthedocs.io/en/latest/api Repositions the traffic light buttons (close, minimize, zoom) for a window using NSLayoutConstraint for robustness against window resizing. It automatically configures the window for a full-size content view and a transparent titlebar. ```APIDOC ## POST /pyqt_liquidglass/setup_traffic_lights_inset ### Description Reposition the traffic light buttons (close, minimize, zoom). Uses NSLayoutConstraint to position the buttons with an offset from their default location. This method is more robust than frame-based positioning as it survives window resizes. ### Method POST ### Endpoint /pyqt_liquidglass/setup_traffic_lights_inset ### Parameters #### Request Body - **window** (QWidget) - Required - The window whose traffic lights to reposition. - **x_offset** (float) - Optional - Horizontal offset in points from the left edge. Defaults to 0.0. - **y_offset** (float) - Optional - Vertical offset in points from the center. Defaults to 0.0. ### Request Example ```json { "window": "", "x_offset": 10.0, "y_offset": 5.0 } ``` ### Response #### Success Response (200) - **success** (bool) - True if the traffic lights were successfully repositioned, False otherwise. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Create Frameless Floating Panel with Glass Effect (Python) Source: https://pyqt-liquidglass.readthedocs.io/en/latest/examples This Python code snippet demonstrates how to create a frameless, draggable floating panel with a glass effect using PySide6 and pyqt-liquidglass. It includes a custom QWidget subclass 'FloatingPanel' that handles mouse events for dragging and applies custom styling. The 'main' function prepares the window for a glass effect and applies it. ```python """Frameless window with glass effect example.""" import sys from PySide6.QtCore import QPoint, Qt from PySide6.QtGui import QMouseEvent from PySide6.QtWidgets import QApplication, QLabel, QPushButton, QVBoxLayout, QWidget import pyqt_liquidglass as glass class FloatingPanel(QWidget): """A frameless, draggable floating panel with glass effect.""" def __init__(self) -> None: super().__init__() self.setWindowTitle("Floating Panel") self.resize(300, 200) self._drag_position: QPoint | None = None self.setStyleSheet("background: transparent;") layout = QVBoxLayout(self) layout.setContentsMargins(24, 24, 24, 24) layout.setSpacing(16) title = QLabel("Floating Panel") title.setAlignment(Qt.AlignmentFlag.AlignCenter) title.setStyleSheet(""" font-size: 18px; font-weight: 600; color: white; background: transparent; """) subtitle = QLabel("Drag anywhere to move") subtitle.setAlignment(Qt.AlignmentFlag.AlignCenter) subtitle.setStyleSheet(""" font-size: 12px; color: rgba(255, 255, 255, 0.7); background: transparent; """) close_button = QPushButton("Close") close_button.setStyleSheet(""" QPushButton { background: rgba(255, 255, 255, 0.15); border: none; border-radius: 8px; padding: 10px 24px; color: white; font-size: 13px; } QPushButton:hover { background: rgba(255, 255, 255, 0.25); } QPushButton:pressed { background: rgba(255, 255, 255, 0.1); } """) close_button.clicked.connect(self.close) layout.addWidget(title) layout.addWidget(subtitle) layout.addStretch() layout.addWidget(close_button) def mousePressEvent(self, event: QMouseEvent) -> None: if event.button() == Qt.MouseButton.LeftButton: self._drag_position = ( event.globalPosition().toPoint() - self.frameGeometry().topLeft() ) event.accept() def mouseMoveEvent(self, event: QMouseEvent) -> None: if ( event.buttons() == Qt.MouseButton.LeftButton and self._drag_position is not None ): self.move(event.globalPosition().toPoint() - self._drag_position) event.accept() def mouseReleaseEvent(self, event: QMouseEvent) -> None: self._drag_position = None def main() -> int: app = QApplication(sys.argv) panel = FloatingPanel() # Prepare with frameless=True to remove window decorations glass.prepare_window_for_glass(panel, frameless=True) panel.show() # Apply glass with rounded corners for the floating look glass.apply_glass_to_window(panel, options=glass.GlassOptions(corner_radius=16.0)) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### prepare_window_for_glass Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_modules/pyqt_liquidglass/helpers Prepares a Qt window for applying glass effects. This function sets necessary Qt widget attributes and configures native macOS NSWindow properties to allow for glass effect rendering underneath the window's content. ```APIDOC ## prepare_window_for_glass ### Description Prepares a Qt window for applying glass effects. This function sets necessary Qt widget attributes and configures native macOS NSWindow properties to allow for glass effect rendering underneath the window's content. ### Method N/A (This is a Python function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from PyQt5 import QtWidgets from pyqt_liquidglass.helpers import prepare_window_for_glass app = QtWidgets.QApplication([]) window = QtWidgets.QWidget() prepare_window_for_glass(window, frameless=False, transparent_titlebar=True, full_size_content=True) window.show() app.exec_() ``` ### Response #### Success Response (N/A) This function does not return a value. #### Response Example N/A ``` -------------------------------- ### GlassOptions Preset Methods Source: https://pyqt-liquidglass.readthedocs.io/en/latest/core_concepts Provides preset methods for common glass effect configurations. Includes options for full window glass, sidebar glass, and custom sidebar configurations with adjustable corner radius and padding. ```python # Full window glass (no corner radius, no padding) options = GlassOptions.window() # Sidebar glass (10pt radius, 9pt padding) options = GlassOptions.sidebar() # Custom sidebar options = GlassOptions.sidebar(corner_radius=16.0, padding=12.0) ``` -------------------------------- ### Create Preset Glass Options Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/core_concepts.rst Provides preset methods for common glass effect configurations. This includes options for full window glass (no radius, no padding) and sidebar glass with customizable radius and padding. ```python # Full window glass (no corner radius, no padding) options = GlassOptions.window() # Sidebar glass (10pt radius, 9pt padding) options = GlassOptions.sidebar() # Custom sidebar options = GlassOptions.sidebar(corner_radius=16.0, padding=12.0) ``` -------------------------------- ### Get macOS version - pyqt-liquidglass Source: https://pyqt-liquidglass.readthedocs.io/en/latest/api Retrieves the macOS version as a tuple of integers (major, minor, patch). If not running on macOS, it returns None. This can be used for version-specific logic. ```python import pyqt_liquidglass macos_version = pyqt_liquidglass.MACOS_VERSION if macos_version: print(f"macOS version: {macos_version[0]}.{macos_version[1]}.{macos_version[2]}") else: print("Not running on macOS or version not available.") ``` -------------------------------- ### Apply Basic Window Glass Effect - Python Source: https://pyqt-liquidglass.readthedocs.io/en/latest/api Demonstrates the basic usage of pyqt-liquidglass to apply the Liquid Glass effect to a QMainWindow. It requires PySide6 or PyQt6 and the pyqt-liquidglass library. The function `prepare_window_for_glass` initializes the window, and `apply_glass_to_window` applies the visual effect. `setup_traffic_lights_inset` can be used to adjust the traffic light button insets. ```python from PySide6.QtWidgets import QApplication, QMainWindow import pyqt_liquidglass as glass app = QApplication([]) window = QMainWindow() window.setWindowTitle("Glass Demo") window.resize(800, 600) glass.prepare_window_for_glass(window) window.show() glass.apply_glass_to_window(window) glass.setup_traffic_lights_inset(window, x_offset=20, y_offset=15) app.exec() ``` -------------------------------- ### Apply Glass to Sidebar with Rounded Corners Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/examples.rst Applies a glass effect with rounded corners to a widget, specifically demonstrated on a sidebar. It utilizes the `apply_glass_to_widget` function from the pyqt-liquidglass library. Dependencies include PySide6 and pyqt-liquidglass. ```python import sys from PySide6.QtWidgets import QApplication, QMainWindow import pyqt_liquidglass as glass class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Sidebar Glass Example") # Create a central widget and a sidebar self.central_widget = QWidget() self.setCentralWidget(self.central_widget) self.sidebar = QWidget(self) self.sidebar.setFixedWidth(100) self.sidebar.setStyleSheet("background: rgba(255, 255, 255, 0.1);") # Layout for the main window layout = QVBoxLayout(self.central_widget) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) # Add sidebar to the layout (example: left side) main_layout = QHBoxLayout() main_layout.addWidget(self.sidebar) main_layout.addWidget(QWidget(), 1) # Stretchable space self.central_widget.setLayout(main_layout) # Prepare window for glass effect glass.prepare_window_for_glass(self) # Apply glass to sidebar with rounded corners glass.apply_glass_to_widget(self.sidebar, options=glass.GlassOptions.sidebar()) def main() -> int: app = QApplication(sys.argv) window = MainWindow() window.setGeometry(100, 100, 800, 600) window.show() # Inset traffic lights to sit nicely on sidebar glass.setup_traffic_lights_inset(window, x_offset=18, y_offset=12) # Apply glass to sidebar with rounded corners glass.apply_glass_to_widget(window.sidebar, options=glass.GlassOptions.sidebar()) return app.exec() if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Prepare Window for Glass Effects (Python) Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_modules/pyqt_liquidglass/helpers Prepares a Qt QWidget (acting as a window) for glass effects by setting necessary Qt attributes and configuring native macOS NSWindow properties. It supports frameless windows, transparent titlebars, and full-size content views. This function should ideally be called before the window is displayed. ```python from __future__ import annotations from typing import TYPE_CHECKING from ._bridge import get_nswindow_from_widget from ._platform import IS_MACOS if TYPE_CHECKING: from ._compat import QtWidgets _NS_FULL_SIZE_CONTENT_VIEW_WINDOW_MASK: int = 1 << 15 _NS_WINDOW_TITLE_HIDDEN: int = 1 _NS_WINDOW_STYLE_MASK_BORDERLESS: int = 0 def prepare_window_for_glass( window: QtWidgets.QWidget, *, frameless: bool = False, transparent_titlebar: bool = True, full_size_content: bool = True, ) -> None: """ Prepare a window for glass effects. Sets the necessary Qt widget attributes and configures the native NSWindow properties for glass effect rendering. Args: window: The window widget to prepare. frameless: If True, remove the window frame entirely using Qt.FramelessWindowHint. transparent_titlebar: If True, make the titlebar transparent on macOS so glass can extend underneath. full_size_content: If True, extend content view to cover the titlebar area. Note: Call this before showing the window for best results. """ from ._compat import QtCore # noqa: PLC0415 window.setAttribute(QtCore.Qt.WidgetAttribute.WA_TranslucentBackground) if frameless: window.setWindowFlag(QtCore.Qt.WindowType.FramelessWindowHint) if not IS_MACOS: return window.show() ns_window = get_nswindow_from_widget(window) if ns_window is None: return if frameless: ns_window.setHasShadow_(False) # ty: ignore # Keep shadow for depth return if full_size_content: current_mask = ns_window.styleMask() # ty: ignore ns_window.setStyleMask_( current_mask | _NS_FULL_SIZE_CONTENT_VIEW_WINDOW_MASK ) if transparent_titlebar: ns_window.setTitlebarAppearsTransparent_(True) # ty: ignore ns_window.setTitleVisibility_(_NS_WINDOW_TITLE_HIDDEN) # ty: ignore ``` -------------------------------- ### prepare_widget_for_glass Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_modules/pyqt_liquidglass/helpers Prepares a Qt widget to have a glass effect applied behind it. It sets attributes to make the widget's background transparent, allowing the glass effect to show through. ```APIDOC ## prepare_widget_for_glass ### Description Prepares a Qt widget to have a glass effect applied behind it. It sets attributes to make the widget's background transparent, allowing the glass effect to show through. ### Method N/A (This is a Python function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from PyQt5 import QtWidgets from pyqt_liquidglass.helpers import prepare_widget_for_glass app = QtWidgets.QApplication([]) widget = QtWidgets.QWidget() prepare_widget_for_glass(widget) # Ensure the widget's parent window is also prepared for transparency # For example: # parent_window = QtWidgets.QWidget() # parent_window.setAttribute(QtCore.Qt.WidgetAttribute.WA_TranslucentBackground) # widget.setParent(parent_window) widget.show() app.exec_() ``` ### Response #### Success Response (N/A) This function does not return a value. #### Response Example N/A ``` -------------------------------- ### Platform Detection Constants Source: https://pyqt-liquidglass.readthedocs.io/en/latest/core_concepts Exposes constants for detecting the operating system and its features. Includes checks for macOS, the macOS version, and the availability of native glass and visual effect views. Functions are safe to call on non-macOS platforms. ```python from pyqt_liquidglass import ( IS_MACOS, MACOS_VERSION, HAS_GLASS_EFFECT, HAS_VISUAL_EFFECT, ) ``` -------------------------------- ### GlassOptions Configuration Source: https://pyqt-liquidglass.readthedocs.io/en/latest/api Provides details on configuring GlassOptions for applying glass effects, including predefined options for sidebars and windows. ```APIDOC ## GlassOptions ### Description Configuration options for glass effects. Allows customization of corner radius, material, blending mode, and padding. ### Class Structure ```python class GlassOptions: def __init__(self, corner_radius: float = 0.0, material: GlassMaterial = GlassMaterial.UNDER_WINDOW_BACKGROUND, blending_mode: BlendingMode = BlendingMode.BEHIND_WINDOW, padding: tuple[float, float, float, float] = (0.0, 0.0, 0.0, 0.0)) -> None ``` ### Parameters - **corner_radius** (float) - Corner radius in points for rounded glass effects. Only applies to NSGlassEffectView on macOS 26+. - **material** (GlassMaterial) - The visual effect material to use. Only applies to NSVisualEffectView fallback on older macOS versions. - **blending_mode** (BlendingMode) - How the effect blends with content. Only applies to NSVisualEffectView fallback. - **padding** (tuple[float, float, float, float]) - Inset padding from widget edges in points (left, top, right, bottom). ### Class Methods #### `sidebar(_corner_radius: float = 10.0, _padding: float = 9.0) -> GlassOptions` Creates options optimized for sidebar glass effects. - **corner_radius** (float) - Corner radius for rounded corners. - **padding** (float) - Uniform padding from all edges. #### `window() -> GlassOptions` Creates options for full window glass effects. ### Enums #### `BlendingMode` Blending modes for visual effect views. Maps to `NSVisualEffectBlendingMode` values. - `BEHIND_WINDOW = 0` - `WITHIN_WINDOW = 1` #### `GlassMaterial` Available materials for glass effects. Maps to `NSVisualEffectMaterial` values for fallback implementation on pre-macOS 26 systems. - `TITLEBAR = 3` - `SELECTION = 4` - `MENU = 5` - `POPOVER = 6` - `SIDEBAR = 7` - `HEADER_VIEW = 10` - `SHEET = 11` - `WINDOW_BACKGROUND = 12` - `HUD = 13` - `FULLSCREEN_UI = 15` - `TOOLTIP = 17` - `CONTENT_BACKGROUND = 18` - `UNDER_WINDOW_BACKGROUND = 21` - `UNDER_PAGE_BACKGROUND = 22` ``` -------------------------------- ### Platform Detection Constants Source: https://pyqt-liquidglass.readthedocs.io/en/latest/_sources/core_concepts.rst Provides constants for detecting the operating system and its version, as well as the availability of native glass effect views. This is useful for conditional logic based on the execution environment. ```python from pyqt_liquidglass import ( IS_MACOS, MACOS_VERSION, HAS_GLASS_EFFECT, HAS_VISUAL_EFFECT, ) ```