Skip to main content

A modern and fully customizable tooltip library for PyQt and PySide

Project description

ZToolTip

PyPI Python Build Coverage License

Forked from pyqttooltip by Niklas Henning

A modern and fully customizable tooltip library for PyQt and PySide

ZToolTip

Features

  • Fixed and automatic placement
  • Customizable triangle
  • Customizable animations and delays
  • Fully customizable and modern UI
  • Works with PyQt5, PyQt6, PySide2, and PySide6

Installation

pip install ztooltip

Usage

from PyQt6.QtWidgets import QMainWindow, QPushButton
from ztooltip import Tooltip, TooltipPlacement


class Window(QMainWindow):
    def __init__(self):
        super().__init__(parent=None)

        # Add button
        self.button = QPushButton('Button', self)
        
        # Add tooltip to button
        self.tooltip = Tooltip(self.button, 'This is a tooltip')

The tooltip will automatically be shown while hovering the widget. If you want to manually show and hide the tooltip, you can use the show() and hide() methods:

tooltip.show()
tooltip.hide()

To delete a tooltip, you can use the deleteLater() method:

tooltip.deleteLater()

To get notified when a tooltip gets shown or hidden, you can subscribe to the shown and hidden signals:

tooltip.shown.connect(lambda: print('shown'))
tooltip.hidden.connect(lambda: print('hidden'))

Customization

  • Setting the widget:
tooltip.setWidget(widget)  # Default: None
  • Setting the text:
tooltip.setText('Text of the tooltip')  # Default: ''
  • Setting the placement:
tooltip.setPlacement(TooltipPlacement.RIGHT)  # Default: TooltipPlacement.AUTO

AVAILABLE PLACEMENTS:
AUTO, LEFT, RIGHT, TOP, BOTTOM

  • Enabling or disabling the triangle:
tooltip.setTriangleEnabled(False)  # Default: True
  • Setting the size of the triangle:
tooltip.setTriangleSize(7)  # Default: 5
  • Setting a duration:
tooltip.setDuration(1000)  # Default: 0

The duration is the time in milliseconds after which the tooltip will start fading out again. If the duration is set to 0, the tooltip will stay visible for as long as the widget is hovered.

  • Adding delays to the fade in / out animations after hovering the widget:
tooltip.setShowDelay(500)  # Default: 50
tooltip.setHideDelay(500)  # Default: 50
  • Setting the durations of the fade in / out animations:
tooltip.setFadeInDuration(250)   # Default: 150
tooltip.setFadeOutDuration(250)  # Default: 150
  • Setting the refresh rate in Hz:
tooltip.setRefreshRate(30)  # Default: 60
  • Setting the border radius:
tooltip.setBorderRadius(0)   # Default: 8
  • Enabling or disabling the border:
tooltip.setBorderEnabled(False)   # Default: True
  • Setting custom colors:
tooltip.setBackgroundColor(QColor('#FCBA03'))   # Default: QColor('#FFFFFF')
tooltip.setTextColor(QColor('#000000'))         # Default: QColor('#373737')
tooltip.setBorderColor(QColor('#A38329'))       # Default: QColor('#CDCFD6')
  • Setting a custom font:
tooltip.setFont(QFont('Consolas', 10))  # Default: QFont('Arial', 9, QFont.Weight.Bold)
  • Applying margins to the content of the tooltip:
tooltip.setMargins(QMargins(10, 8, 10, 8))  # Default: QMargins(12, 8, 12, 7)
  • Setting a maximum width:
tooltip.setMaximumWidth(150)  # Default: 16777215 (QWIDGETSIZE_MAX)
  • Enabling or disabling text centering for wrapped text:
tooltip.setTextCenteringEnabled(False)  # Default: True
  • Enabling or disabling the drop shadow:
tooltip.setDropShadowEnabled(False)  # Default: True
  • Changing the drop shadow strength:
tooltip.setDropShadowStrength(3.5)  # Default: 2.0
  • Making the tooltip translucent:
tooltip.setOpacity(0.8)  # Default: 1.0


Other customization options:

Option Description Default
setShowingOnDisabled() Whether the tooltips should also be shown on disabled widgets False
setFadeInEasingCurve() The easing curve of the fade in animation QEasingCurve.Type.Linear
setFadeOutEasingCurve() The easing curve of the fade out animation QEasingCurve.Type.Linear
setMarginLeft() Set left margin individually 12
setMarginRight() Set right margin individually 12
setMarginTop() Set top margin individually 8
setMarginBottom() Set bottom margin individually 7

Demo

https://github.com/user-attachments/assets/04af0cfc-32fd-4aa7-80e6-6f263e44af67

The demos for PyQt5, PyQt6, and PySide6 can be found in the demo folder.

To keep the demo simple, only the most important features are included. To get an overview of all the customization options, check out the documentation above.

Tests

Installing the required test dependencies PyQt6, pytest, and coveragepy:

pip install PyQt6 pytest coverage

To run the tests with coverage, clone this repository, go into the main directory and run:

coverage run -m pytest
coverage report --ignore-errors -m

License

This software is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ztooltip-2.0.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ztooltip-2.0.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file ztooltip-2.0.0.tar.gz.

File metadata

  • Download URL: ztooltip-2.0.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for ztooltip-2.0.0.tar.gz
Algorithm Hash digest
SHA256 451a340ab5361d9e89398222943d48ba631d8f1e8053a8e705459a8cf9170607
MD5 963d82dc57e4f60a939097fc2dfd2010
BLAKE2b-256 c58f0245b9474305bc3f24e044ebd5e1bd5257b2bc1468cb13ea201518fe490c

See more details on using hashes here.

File details

Details for the file ztooltip-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: ztooltip-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for ztooltip-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91fd6338d3d8a3d7595afe0e9a56bcef5fce5e478342561792cf7d383a41354d
MD5 546411c329691523f514cd8fca0e8e51
BLAKE2b-256 1d0b22e9cae5a46510823da3bd4300659fff58dc9b3ec6ac8792ab317517549d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page