### Position Toasts Relative to a Widget in PyQt Source: https://context7.com/niklashenning/pyqttoast/llms.txt Demonstrates how to make toast notifications appear relative to a specific QWidget. This is achieved by calling `Toast.setPositionRelativeToWidget()` with the desired widget. The toast can also be configured to move with the widget using `Toast.setMovePositionWithWidget()`. This example shows a toast appearing within a panel widget. ```python from PyQt6.QtWidgets import QMainWindow, QApplication, QWidget, QVBoxLayout, QPushButton from pyqttoast import Toast, ToastPreset, ToastPosition class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setGeometry(100, 100, 800, 600) # Create a panel widget self.panel = QWidget(self) self.panel.setGeometry(200, 100, 400, 400) self.panel.setStyleSheet("background-color: #f0f0f0; border: 1px solid #ccc;") # Set toasts to appear relative to the panel Toast.setPositionRelativeToWidget(self.panel) Toast.setPosition(ToastPosition.BOTTOM_RIGHT) Toast.setMovePositionWithWidget(True) # Move with panel if resized def show_toast_in_panel(self): toast = Toast(self) toast.setTitle('Panel Notification') toast.setText('This toast appears within the panel bounds.') toast.applyPreset(ToastPreset.SUCCESS) toast.show() def clear_widget_positioning(self): # Reset to screen-relative positioning Toast.setPositionRelativeToWidget(None) app = QApplication([]) window = MainWindow() window.show() window.show_toast_in_panel() app.exec() ``` -------------------------------- ### Create and Display Toast Notification with PyQt6 Source: https://context7.com/niklashenning/pyqttoast/llms.txt Demonstrates how to create and display a toast notification using the Toast class in PyQt6. It shows how to set the parent widget, duration, title, text, and apply a success preset. Each toast requires a new instance. ```python from PyQt6.QtWidgets import QMainWindow, QPushButton, QApplication from pyqttoast import Toast, ToastPreset class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Toast Example") self.setGeometry(100, 100, 400, 300) button = QPushButton("Show Toast", self) button.setGeometry(150, 130, 100, 30) button.clicked.connect(self.show_toast) def show_toast(self): toast = Toast(self) toast.setDuration(5000) # Hide after 5 seconds toast.setTitle('Success! Operation completed.') toast.setText('Your changes have been saved.') toast.applyPreset(ToastPreset.SUCCESS) toast.show() if __name__ == "__main__": app = QApplication([]) window = MainWindow() window.show() app.exec() ``` -------------------------------- ### Show a Basic Toast Notification in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Demonstrates how to import the Toast class, instantiate it, set its duration, title, text, apply a preset style, and display the notification. Note that each toast instance can only be shown once. ```python from PyQt6.QtWidgets import QMainWindow, QPushButton from pyqttoast import Toast, ToastPreset class Window(QMainWindow): def __init__(self): super().__init__(parent=None) # Add button and connect click event self.button = QPushButton(self) self.button.setText('Show toast') self.button.clicked.connect(self.show_toast) # Shows a toast notification every time the button is clicked def show_toast(self): toast = Toast(self) toast.setDuration(5000) # Hide after 5 seconds toast.setTitle('Success! Confirmation email sent.') toast.setText('Check your email to complete signup.') toast.applyPreset(ToastPreset.SUCCESS) # Apply style preset toast.show() ``` -------------------------------- ### Customize PyQtToast Appearance with Colors and Fonts Source: https://context7.com/niklashenning/pyqttoast/llms.txt Demonstrates how to extensively customize the visual appearance of a PyQtToast notification. This includes setting background and text colors, fonts, border radius, duration bar appearance, margins, and size constraints. Configuration should be done before calling the `show()` method. ```python from PyQt6.QtWidgets import QMainWindow, QApplication from PyQt6.QtGui import QColor, QFont from PyQt6.QtCore import QMargins from pyqttoast import Toast class MainWindow(QMainWindow): def show_custom_styled_toast(self): toast = Toast(self) # Set content toast.setTitle('Custom Styled Toast') toast.setText('Fully customized appearance.') # Colors toast.setBackgroundColor(QColor('#1a1a2e')) toast.setTitleColor(QColor('#edf2f4')) toast.setTextColor(QColor('#8d99ae')) toast.setDurationBarColor(QColor('#e63946')) toast.setIconSeparatorColor(QColor('#4a4e69')) toast.setCloseButtonIconColor(QColor('#f1faee')) # Fonts title_font = QFont('Segoe UI', 11, QFont.Weight.Bold) text_font = QFont('Segoe UI', 9) toast.setTitleFont(title_font) toast.setTextFont(text_font) # Border radius for rounded corners toast.setBorderRadius(8) # Default: 0 # Duration bar settings toast.setShowDurationBar(True) toast.setDuration(6000) toast.setResetDurationOnHover(True) # Pause on mouse hover # Margins toast.setMargins(QMargins(25, 20, 15, 20)) toast.setTextSectionSpacing(10) # Space between title and text # Size constraints toast.setMinimumWidth(300) toast.setMaximumWidth(400) toast.setMinimumHeight(60) toast.setMaximumHeight(150) # Animation durations toast.setFadeInDuration(300) # Default: 250 toast.setFadeOutDuration(200) # Default: 250 # Window behavior toast.setStayOnTop(True) # Stay above other windows toast.show() app = QApplication([]) window = MainWindow() window.show_custom_styled_toast() app.exec() ``` -------------------------------- ### Configure Global PyQt Toast Settings Source: https://context7.com/niklashenning/pyqttoast/llms.txt Details static methods on the Toast class for global configuration of toast notifications. This includes setting the maximum number of toasts displayed simultaneously, spacing between toasts, screen offsets, and screen positioning. It also covers options for always showing on the main screen and positioning relative to a widget. ```python from PyQt6.QtWidgets import QMainWindow, QApplication, QWidget from pyqttoast import Toast, ToastPreset, ToastPosition class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setup_toast_settings() def setup_toast_settings(self): # Maximum toasts shown at once (others queue) Toast.setMaximumOnScreen(5) # Default: 3 # Vertical spacing between toasts Toast.setSpacing(15) # Default: 10 # Offset from screen edge Toast.setOffset(30, 50) # Default: 20, 45 # Or set individually: # Toast.setOffsetX(30) # Toast.setOffsetY(50) # Position on screen Toast.setPosition(ToastPosition.BOTTOM_RIGHT) # Always show on primary monitor Toast.setAlwaysOnMainScreen(True) # Default: False # Position relative to a specific widget # Toast.setPositionRelativeToWidget(some_widget) def show_multiple_toasts(self): for i in range(7): toast = Toast(self) toast.setTitle(f'Toast #{i + 1}') toast.setText('Queue demonstration - max 5 on screen.') toast.setDuration(4000) toast.applyPreset(ToastPreset.INFORMATION) toast.show() def get_toast_counts(self): visible = Toast.getVisibleCount() queued = Toast.getQueuedCount() total = Toast.getCount() print(f"Visible: {visible}, Queued: {queued}, Total: {total}") def reset_all_toasts(self): # Reset all static settings and clear toasts Toast.reset() app = QApplication([]) window = MainWindow() window.show_multiple_toasts() app.exec() ``` -------------------------------- ### Apply Pre-configured Toast Styles with PyQt6 Source: https://context7.com/niklashenning/pyqttoast/llms.txt Illustrates the use of the ToastPreset enum to apply predefined styles for different notification types like success, error, warning, and information, including dark variants. These presets automatically configure icons, colors, and duration bar styling. ```python from PyQt6.QtWidgets import QMainWindow, QApplication from pyqttoast import Toast, ToastPreset class MainWindow(QMainWindow): def __init__(self): super().__init__() def show_success(self): toast = Toast(self) toast.setTitle('Success!') toast.setText('File uploaded successfully.') toast.applyPreset(ToastPreset.SUCCESS) toast.show() def show_error(self): toast = Toast(self) toast.setTitle('Error!') toast.setText('Failed to connect to server.') toast.applyPreset(ToastPreset.ERROR) toast.show() def show_warning_dark(self): toast = Toast(self) toast.setTitle('Warning') toast.setText('Low disk space remaining.') toast.applyPreset(ToastPreset.WARNING_DARK) toast.show() def show_info_dark(self): toast = Toast(self) toast.setTitle('Information') toast.setText('Update available.') toast.applyPreset(ToastPreset.INFORMATION_DARK) toast.show() # Usage app = QApplication([]) window = MainWindow() window.show_success() window.show_error() app.exec() ``` -------------------------------- ### Set Custom Icons for PyQt Toasts Source: https://context7.com/niklashenning/pyqttoast/llms.txt Demonstrates how to use built-in icons or custom QPixmap images for toast notifications. Icons can be displayed, sized, and colored. Custom icons can retain their original colors by setting the icon color to None. The display of the icon separator can also be controlled. ```python from PyQt6.QtWidgets import QMainWindow, QApplication from PyQt6.QtGui import QPixmap, QColor from PyQt6.QtCore import QSize from pyqttoast import Toast, ToastIcon class MainWindow(QMainWindow): def show_with_builtin_icon(self): toast = Toast(self) toast.setTitle('Download Complete') toast.setText('Your file is ready.') toast.setIcon(ToastIcon.SUCCESS) toast.setShowIcon(True) toast.setIconSize(QSize(20, 20)) toast.setIconColor(QColor('#00AA00')) toast.show() def show_with_custom_icon(self): toast = Toast(self) toast.setTitle('Custom Notification') toast.setText('Using a custom icon.') toast.setIcon(QPixmap('path/to/custom/icon.png')) toast.setShowIcon(True) toast.setIconColor(None) # None preserves original icon colors toast.show() def show_without_separator(self): toast = Toast(self) toast.setTitle('Minimal Style') toast.setText('Icon without separator line.') toast.setIcon(ToastIcon.INFORMATION) toast.setShowIcon(True) toast.setShowIconSeparator(False) toast.show() app = QApplication([]) window = MainWindow() window.show_with_builtin_icon() app.exec() ``` -------------------------------- ### Apply Style Preset in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet demonstrates how to apply a predefined style preset to a PyQt toast notification. It allows selecting from various presets like ERROR, WARNING, SUCCESS, and INFORMATION, including dark mode variations. This simplifies the process of applying consistent styling. ```python toast.applyPreset(ToastPreset.ERROR) ``` -------------------------------- ### Configure Toast Display Position Globally with PyQt6 Source: https://context7.com/niklashenning/pyqttoast/llms.txt Shows how to globally configure the display position of toast notifications using the ToastPosition enum and the static `Toast.setPosition()` method. It demonstrates setting the position to TOP_RIGHT and mentions other available options. ```python from PyQt6.QtWidgets import QApplication, QMainWindow from pyqttoast import Toast, ToastPreset, ToastPosition class MainWindow(QMainWindow): def __init__(self): super().__init__() # Set toast position globally (affects all toasts) Toast.setPosition(ToastPosition.TOP_RIGHT) # Additional position options: # Toast.setPosition(ToastPosition.BOTTOM_LEFT) # Toast.setPosition(ToastPosition.BOTTOM_MIDDLE) # Toast.setPosition(ToastPosition.BOTTOM_RIGHT) # Default # Toast.setPosition(ToastPosition.TOP_LEFT) # Toast.setPosition(ToastPosition.TOP_MIDDLE) # Toast.setPosition(ToastPosition.CENTER) def show_toast(self): toast = Toast(self) toast.setTitle('Notification') toast.setText('This toast appears in top right corner.') toast.applyPreset(ToastPreset.INFORMATION) toast.show() app = QApplication([]) window = MainWindow() window.show_toast() app.exec() ``` -------------------------------- ### Add and Show Toast Icon Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Demonstrates how to add a predefined icon (like SUCCESS) or a custom QPixmap to a toast notification and control its visibility. The default icon is INFORMATION. ```python toast.setIcon(ToastIcon.SUCCESS) # Default: ToastIcon.INFORMATION ttoast.setShowIcon(True) # Default: False # Or setting a custom icon: ttoast.setIcon(QPixmap('path/to/your/icon.png')) ``` -------------------------------- ### Configure Toast Notification Position (Static) Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Shows how to set the default position for all toast notifications using a static method. This affects all subsequent toasts unless overridden individually. Several predefined positions are available. ```python Toast.setPosition(ToastPosition.BOTTOM_MIDDLE) # Default: ToastPosition.BOTTOM_RIGHT ``` -------------------------------- ### Configure Maximum Simultaneous Toasts (Static) Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Sets a limit on the number of toast notifications that can be displayed concurrently. If this limit is reached, new toasts are queued. This is a static configuration. ```python Toast.setMaximumOnScreen(5) # Default: 3 ``` -------------------------------- ### Create Permanent and Semi-Permanent PyQtToasts Source: https://context7.com/niklashenning/pyqttoast/llms.txt Illustrates how to create toasts that remain visible until manually closed or for an extended duration. Setting the duration to 0 makes a toast permanent, while a large duration value combined with `setResetDurationOnHover(True)` creates a semi-permanent toast that pauses on hover. ```python from PyQt6.QtWidgets import QMainWindow, QApplication from pyqttoast import Toast, ToastPreset class MainWindow(QMainWindow): def show_permanent_toast(self): toast = Toast(self) toast.setTitle('Action Required') toast.setText('Please review and confirm the changes before proceeding.') toast.setDuration(0) # 0 = permanent, no auto-dismiss toast.setShowDurationBar(False) # No progress bar for permanent toast toast.applyPreset(ToastPreset.WARNING) toast.show() def show_semi_permanent_toast(self): toast = Toast(self) toast.setTitle('Long Notification') toast.setText('This will stay for 30 seconds.') toast.setDuration(30000) # 30 seconds toast.setResetDurationOnHover(True) # Resets when user hovers toast.applyPreset(ToastPreset.INFORMATION) toast.show() app = QApplication([]) window = MainWindow() window.show_permanent_toast() app.exec() ``` -------------------------------- ### Configure Toast Offset (Static) Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Sets the horizontal (x) and vertical (y) offset for toast notification positions. This static configuration allows fine-tuning of the toast's placement relative to its designated screen or widget. ```python Toast.setOffset(30, 55) # Default: 20, 45 ``` -------------------------------- ### Configure Toast Notification Main Screen Behavior (Static) Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Configures whether toast notifications should always appear on the main screen. This is a static setting that applies globally to all toasts in the application. ```python Toast.setAlwaysOnMainScreen(True) # Default: False ``` -------------------------------- ### Handle PyQtToast Dismissal with the Closed Signal Source: https://context7.com/niklashenning/pyqttoast/llms.txt Explains how to use the `Toast.closed` signal to execute custom logic when a toast is dismissed. This signal is emitted regardless of whether the toast expires naturally or is closed by the user. It's useful for cleanup tasks or triggering subsequent actions. ```python from PyQt6.QtWidgets import QMainWindow, QApplication from pyqttoast import Toast, ToastPreset class MainWindow(QMainWindow): def __init__(self): super().__init__() self.notification_count = 0 def show_toast_with_callback(self): toast = Toast(self) toast.setTitle('Task Complete') toast.setText('Processing finished successfully.') toast.setDuration(3000) toast.applyPreset(ToastPreset.SUCCESS) # Connect to closed signal toast.closed.connect(self.on_toast_closed) toast.closed.connect(lambda: print("Toast was dismissed")) toast.show() self.notification_count += 1 def on_toast_closed(self): self.notification_count -= 1 print(f"Toast closed. Active notifications: {self.notification_count}") # Perform cleanup, update UI, trigger next action, etc. app = QApplication([]) window = MainWindow() window.show_toast_with_callback() app.exec() ``` -------------------------------- ### Set Toast Size Constraints in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet allows setting size constraints for a PyQt toast notification. It provides options for setting minimum and maximum width and height, as well as a fixed size. This helps control the appearance and layout of the toast. ```python # Minimum and maximum size toast.setMinimumWidth(100) toast.setMaximumWidth(350) toast.setMinimumHeight(50) toast.setMaximumHeight(120) # Fixed size (not recommended) toast.setFixedSize(QSize(350, 80)) ``` -------------------------------- ### Configure Toast Notification Widget Relative Positioning (Static) Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Enables positioning toast notifications relative to a specific widget instead of a screen. This is a static configuration that needs a widget instance to be passed. ```python Toast.setPositionRelativeToWidget(some_widget) # Default: None ``` -------------------------------- ### Configure Vertical Spacing Between Toasts (Static) Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Adjusts the vertical space between multiple toast notifications displayed on the screen. This static setting affects the layout of all concurrent toasts. ```python Toast.setSpacing(20) # Default: 10 ``` -------------------------------- ### Set Custom Colors in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet demonstrates how to customize the colors of various elements within a PyQt toast notification. It allows setting the background, title, text, duration bar, icon, icon separator, and close button icon colors. It uses QColor objects to define the desired colors. ```python toast.setBackgroundColor(QColor('#292929')) # Default: #E7F4F9 toast.setTitleColor(QColor('#FFFFFF')) # Default: #000000 toast.setTextColor(QColor('#D0D0D0')) # Default: #5C5C5C toast.setDurationBarColor(QColor('#3E9141')) # Default: #5C5C5C toast.setIconColor(QColor('#3E9141')) # Default: #5C5C5C toast.setIconSeparatorColor(QColor('#585858')) # Default: #D9D9D9 toast.setCloseButtonIconColor(QColor('#C9C9C9')) # Default: #000000 ``` -------------------------------- ### Set Toast Duration to Infinite Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Configures a toast notification to remain visible indefinitely until manually closed. This is achieved by setting the duration to 0. ```python toast.setDuration(0) # Default: 5000 ``` -------------------------------- ### Control Close Button Position for PyQt Toasts Source: https://context7.com/niklashenning/pyqttoast/llms.txt Explains how to control the vertical alignment of the close button in toast notifications using the ToastButtonAlignment enum. It also shows how to completely hide the close button. Options include TOP, MIDDLE, and BOTTOM alignment, with MIDDLE being the default. ```python from PyQt6.QtWidgets import QMainWindow, QApplication from PyQt6.QtCore import QSize from pyqttoast import Toast, ToastPreset, ToastButtonAlignment class MainWindow(QMainWindow): def show_toast_close_top(self): toast = Toast(self) toast.setTitle('Close Button Top') toast.setText('The X button is aligned to the top.') toast.setCloseButtonAlignment(ToastButtonAlignment.TOP) # Default toast.applyPreset(ToastPreset.INFORMATION) toast.show() def show_toast_close_middle(self): toast = Toast(self) toast.setTitle('Close Button Middle') toast.setText('The X button is vertically centered.') toast.setCloseButtonAlignment(ToastButtonAlignment.MIDDLE) toast.setCloseButtonSize(QSize(28, 28)) toast.applyPreset(ToastPreset.INFORMATION) toast.show() def show_toast_no_close_button(self): toast = Toast(self) toast.setTitle('No Close Button') toast.setText('This toast has no close button.') toast.setShowCloseButton(False) toast.setDuration(3000) toast.applyPreset(ToastPreset.WARNING) toast.show() app = QApplication([]) window = MainWindow() window.show_toast_close_middle() app.exec() ``` -------------------------------- ### Show/Hide Icon Separator in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet controls the visibility of the icon separator in a PyQt toast notification. It allows enabling or disabling the separator, which visually separates the icon from the text. The default setting is to show the separator (True). ```python toast.setShowIconSeparator(False) # Default: True ``` -------------------------------- ### Enable or Disable Toast Duration Bar Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md Controls the visibility of the progress bar that indicates the remaining duration of a toast notification. This can be toggled on or off. ```python toast.setShowDurationBar(False) # Default: True ``` -------------------------------- ### Set Icon Size in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet shows how to modify the size of the icon displayed in a PyQt toast notification. It uses the QSize class to define the desired width and height of the icon. The default icon size is QSize(18, 18). ```python toast.setIconSize(QSize(14, 14)) # Default: QSize(18, 18) ``` -------------------------------- ### Show/Hide Close Button in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet controls the visibility of the close button in a PyQt toast notification. It allows enabling or disabling the close button, providing the user with the option to dismiss the notification. The default setting is to show the close button (True). ```python toast.setShowCloseButton(False) # Default: True ``` -------------------------------- ### Set Fade Animation Duration in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet customizes the duration of the fade-in and fade-out animations for a PyQt toast notification. It allows setting the animation duration in milliseconds. The default duration for both fade-in and fade-out is 250 milliseconds. ```python toast.setFadeInDuration(100) # Default: 250 toast.setFadeOutDuration(150) # Default: 250 ``` -------------------------------- ### Set Border Radius in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet modifies the corner rounding of a PyQt toast notification. It allows setting the border radius to create rounded corners. The default value is 0, resulting in square corners. ```python toast.setBorderRadius(3) # Default: 0 ``` -------------------------------- ### Set Custom Fonts in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet shows how to customize the fonts used in a PyQt toast notification. It allows setting the title and text fonts using QFont objects. The default font for the title is Arial, 9, Bold, and for the text is Arial, 9. ```python # Init font font = QFont('Times', 10, QFont.Weight.Bold) # Set fonts toast.setTitleFont(font) # Default: QFont('Arial', 9, QFont.Weight.Bold) toast.setTextFont(font) # Default: QFont('Arial', 9) ``` -------------------------------- ### Set Close Button Alignment in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet configures the alignment of the close button within a PyQt toast notification. It allows positioning the close button at the top, middle, or bottom of the notification. The default alignment is TOP. ```python toast.setCloseButtonAlignment(ToastButtonAlignment.MIDDLE) # Default: ToastButtonAlignment.TOP ``` -------------------------------- ### Set Duration Reset on Hover in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet configures whether the toast notification's duration resets when the user hovers over it. When set to False, the duration will not reset on hover. The default setting is to reset the duration on hover (True). ```python toast.setResetDurationOnHover(False) # Default: True ``` -------------------------------- ### Set Icon Color in PyQt Source: https://github.com/niklashenning/pyqttoast/blob/master/README.md This code snippet demonstrates how to customize the icon color within a PyQt toast notification. It allows setting a specific color or disabling recoloring by setting the color to None. The default color is #5C5C5C. ```python toast.setIconColor(None) # Default: #5C5C5C ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.