# PyQt Tooltip
[![PyPI](https://img.shields.io/badge/pypi-v1.0.0-blue)](https://pypi.org/project/pyqttooltip/)
[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/niklashenning/pyqttooltip)
[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/niklashenning/pyqttooltip)
[![Coverage](https://img.shields.io/badge/coverage-92%25-green)](https://github.com/niklashenning/pyqttooltip)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/niklashenning/pyqttooltip/blob/master/LICENSE)
A modern and fully customizable tooltip library for PyQt and PySide
![pyqttooltip](https://github.com/user-attachments/assets/0313ffc7-560b-4665-a652-e1e2601fcbaa)
## Features
- Fixed and automatic placement
- Supports fallback placements
- Customizable triangle
- Customizable animations and delays
- Fully customizable and modern UI
- Works with `PyQt5`, `PyQt6`, `PySide2`, and `PySide6`
## Installation
```
pip install pyqttooltip
```
## Usage
```python
from PyQt6.QtWidgets import QMainWindow, QPushButton
from pyqttooltip 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:
```python
tooltip.show()
tooltip.hide()
```
To delete a tooltip, you can use the `deleteLater()` method:
```python
tooltip.deleteLater()
```
To get notified when a tooltip gets shown or hidden, you can subscribe to the `shown` and `hidden` signals:
```python
tooltip.shown.connect(lambda: print('shown'))
tooltip.hidden.connect(lambda: print('hidden'))
```
## Customization
* **Setting the widget:**
```python
tooltip.setWidget(widget) # Default: None
```
* **Setting the text:**
```python
tooltip.setText('Text of the tooltip') # Default: ''
```
* **Setting the placement:**
```python
tooltip.setPlacement(TooltipPlacement.RIGHT) # Default: TooltipPlacement.AUTO
```
> **AVAILABLE PLACEMENTS:** <br> `AUTO`, `LEFT`, `RIGHT`, `TOP`, `BOTTOM`
* **Setting the fallback placements:**
```python
tooltip.setFallbackPlacements([TooltipPlacement.TOP, TooltipPlacement.BOTTOM]) # Default: []
```
> If the tooltip doesn't fit on the screen with the primary placement, one of the
> fallback placements will be chosen instead in the order of the provided list.
> <br> To get the current placement of the tooltip, you can use the `getActualPlacement()` method.
* **Enabling or disabling the triangle:**
```python
tooltip.setTriangleEnabled(False) # Default: True
```
* **Setting the size of the triangle:**
```python
tooltip.setTriangleSize(7) # Default: 5
```
* **Setting a duration:**
```python
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.
* **Setting the offsets:**
```python
# Setting the offset for a specific placement
tooltip.setOffsetByPlacement(TooltipPlacement.LEFT, QPoint(-10, 5))
# Using a dict that specifies the offset for each placement you want to set
offsets = {
TooltipPlacement.LEFT: QPoint(-10, 5),
TooltipPlacement.RIGHT: QPoint(10, 5),
TooltipPlacement.TOP: QPoint(5, -10),
TooltipPlacement.BOTTOM: QPoint(5, 10)
}
tooltip.setOffsets(offsets)
# Setting the offsets for all the placements to a single value
tooltip.setOffsetsAll(QPoint(10, 5))
```
> Each placement / side has its own offset to allow for full customizability.
> Each offset is a QPoint, which is made up of an x and y value.
> <br> By default, all the offsets are set to `QPoint(0, 0)`.
* **Adding delays to the fade in / out animations after hovering the widget:**
```python
tooltip.setShowDelay(500) # Default: 50
tooltip.setHideDelay(500) # Default: 50
```
* **Setting the durations of the fade in / out animations:**
```python
tooltip.setFadeInDuration(250) # Default: 150
tooltip.setFadeOutDuration(250) # Default: 150
```
* **Setting the border radius:**
```python
tooltip.setBorderRadius(0) # Default: 2
```
* **Enabling or disabling the border:**
```python
tooltip.setBorderEnabled(True) # Default: False
```
* **Setting custom colors:**
```python
tooltip.setBackgroundColor(QColor('#FCBA03')) # Default: QColor('#111214')
tooltip.setTextColor(QColor('#000000')) # Default: QColor('#CFD2D5')
tooltip.setBorderColor(QColor('#A38329')) # Default: QColor('#403E41')
```
* **Setting a custom font:**
```python
tooltip.setFont(QFont('Consolas', 10)) # Default: QFont('Arial', 9, QFont.Weight.Bold)
```
* **Applying margins to the content of the tooltip:**
```python
tooltip.setMargins(QMargins(10, 8, 10, 8)) # Default: QMargins(12, 8, 12, 7)
```
* **Setting a maximum width:**
```python
tooltip.setMaximumWidth(150) # Default: 16777215 (QWIDGETSIZE_MAX)
```
* **Enabling or disabling text centering for wrapped text:**
```python
tooltip.setTextCenteringEnabled(False) # Default: True
```
* **Enabling or disabling the drop shadow:**
```python
tooltip.setDropShadowEnabled(False) # Default: True
```
* **Changing the drop shadow strength:**
```python
tooltip.setDropShadowStrength(3.5) # Default: 2.0
```
* **Making the tooltip translucent:**
```python
tooltip.setOpacity(0.8) # Default: 1.0
```
**<br>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/fa768d30-f3cc-4883-aa8b-fed3a8824b23
The demos for PyQt5, PyQt6, and PySide6 can be found in the [demo](https://github.com/niklashenning/pyqttooltip/blob/master/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](https://pypi.org/project/PyQt6/), [pytest](https://github.com/pytest-dev/pytest), and [coveragepy](https://github.com/nedbat/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](https://github.com/niklashenning/pyqttooltip/blob/master/LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/niklashenning/pyqttooltip",
"name": "pyqttooltip",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "python, pyqt, qt, tooltip, modern",
"author": "Niklas Henning",
"author_email": "business@niklashenning.com",
"download_url": "https://files.pythonhosted.org/packages/56/2d/1db43cbe060c520de42b031eacad4828946c47d63b58fa75dac629b4ac41/pyqttooltip-1.0.0.tar.gz",
"platform": null,
"description": "\r\n# PyQt Tooltip\r\n\r\n[![PyPI](https://img.shields.io/badge/pypi-v1.0.0-blue)](https://pypi.org/project/pyqttooltip/)\r\n[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/niklashenning/pyqttooltip)\r\n[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/niklashenning/pyqttooltip)\r\n[![Coverage](https://img.shields.io/badge/coverage-92%25-green)](https://github.com/niklashenning/pyqttooltip)\r\n[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/niklashenning/pyqttooltip/blob/master/LICENSE)\r\n\r\n\r\nA modern and fully customizable tooltip library for PyQt and PySide\r\n\r\n![pyqttooltip](https://github.com/user-attachments/assets/0313ffc7-560b-4665-a652-e1e2601fcbaa)\r\n\r\n## Features\r\n- Fixed and automatic placement\r\n- Supports fallback placements\r\n- Customizable triangle\r\n- Customizable animations and delays\r\n- Fully customizable and modern UI\r\n- Works with `PyQt5`, `PyQt6`, `PySide2`, and `PySide6`\r\n\r\n## Installation\r\n```\r\npip install pyqttooltip\r\n```\r\n\r\n## Usage\r\n```python\r\nfrom PyQt6.QtWidgets import QMainWindow, QPushButton\r\nfrom pyqttooltip import Tooltip, TooltipPlacement\r\n\r\n\r\nclass Window(QMainWindow):\r\n def __init__(self):\r\n super().__init__(parent=None)\r\n\r\n # Add button\r\n self.button = QPushButton('Button', self)\r\n \r\n # Add tooltip to button\r\n self.tooltip = Tooltip(self.button, 'This is a tooltip')\r\n```\r\n\r\n\r\nThe tooltip will automatically be shown while hovering the widget. If you want to manually\r\nshow and hide the tooltip, you can use the `show()` and `hide()` methods:\r\n```python\r\ntooltip.show()\r\ntooltip.hide()\r\n```\r\n\r\n\r\nTo delete a tooltip, you can use the `deleteLater()` method:\r\n```python\r\ntooltip.deleteLater()\r\n```\r\n\r\n\r\nTo get notified when a tooltip gets shown or hidden, you can subscribe to the `shown` and `hidden` signals:\r\n```python\r\ntooltip.shown.connect(lambda: print('shown'))\r\ntooltip.hidden.connect(lambda: print('hidden'))\r\n```\r\n\r\n\r\n## Customization\r\n\r\n* **Setting the widget:**\r\n```python\r\ntooltip.setWidget(widget) # Default: None\r\n```\r\n\r\n\r\n* **Setting the text:**\r\n```python\r\ntooltip.setText('Text of the tooltip') # Default: ''\r\n```\r\n\r\n\r\n* **Setting the placement:**\r\n```python\r\ntooltip.setPlacement(TooltipPlacement.RIGHT) # Default: TooltipPlacement.AUTO\r\n```\r\n> **AVAILABLE PLACEMENTS:** <br> `AUTO`, `LEFT`, `RIGHT`, `TOP`, `BOTTOM`\r\n\r\n\r\n* **Setting the fallback placements:**\r\n```python\r\ntooltip.setFallbackPlacements([TooltipPlacement.TOP, TooltipPlacement.BOTTOM]) # Default: []\r\n```\r\n> If the tooltip doesn't fit on the screen with the primary placement, one of the\r\n> fallback placements will be chosen instead in the order of the provided list.\r\n> <br> To get the current placement of the tooltip, you can use the `getActualPlacement()` method.\r\n\r\n\r\n* **Enabling or disabling the triangle:**\r\n```python\r\ntooltip.setTriangleEnabled(False) # Default: True\r\n```\r\n\r\n\r\n* **Setting the size of the triangle:**\r\n```python\r\ntooltip.setTriangleSize(7) # Default: 5\r\n```\r\n\r\n\r\n* **Setting a duration:**\r\n```python\r\ntooltip.setDuration(1000) # Default: 0\r\n```\r\n> The duration is the time in milliseconds after which the tooltip will start fading out again.\r\n> If the duration is set to `0`, the tooltip will stay visible for as long as the widget is hovered.\r\n\r\n\r\n* **Setting the offsets:**\r\n```python\r\n# Setting the offset for a specific placement\r\ntooltip.setOffsetByPlacement(TooltipPlacement.LEFT, QPoint(-10, 5))\r\n\r\n# Using a dict that specifies the offset for each placement you want to set\r\noffsets = {\r\n TooltipPlacement.LEFT: QPoint(-10, 5),\r\n TooltipPlacement.RIGHT: QPoint(10, 5),\r\n TooltipPlacement.TOP: QPoint(5, -10),\r\n TooltipPlacement.BOTTOM: QPoint(5, 10)\r\n}\r\ntooltip.setOffsets(offsets)\r\n\r\n# Setting the offsets for all the placements to a single value\r\ntooltip.setOffsetsAll(QPoint(10, 5))\r\n```\r\n> Each placement / side has its own offset to allow for full customizability.\r\n> Each offset is a QPoint, which is made up of an x and y value.\r\n> <br> By default, all the offsets are set to `QPoint(0, 0)`.\r\n\r\n\r\n* **Adding delays to the fade in / out animations after hovering the widget:**\r\n```python\r\ntooltip.setShowDelay(500) # Default: 50\r\ntooltip.setHideDelay(500) # Default: 50\r\n```\r\n\r\n\r\n* **Setting the durations of the fade in / out animations:**\r\n```python\r\ntooltip.setFadeInDuration(250) # Default: 150\r\ntooltip.setFadeOutDuration(250) # Default: 150\r\n```\r\n\r\n\r\n* **Setting the border radius:**\r\n```python\r\ntooltip.setBorderRadius(0) # Default: 2\r\n```\r\n\r\n\r\n* **Enabling or disabling the border:**\r\n```python\r\ntooltip.setBorderEnabled(True) # Default: False\r\n```\r\n\r\n\r\n* **Setting custom colors:**\r\n```python\r\ntooltip.setBackgroundColor(QColor('#FCBA03')) # Default: QColor('#111214')\r\ntooltip.setTextColor(QColor('#000000')) # Default: QColor('#CFD2D5')\r\ntooltip.setBorderColor(QColor('#A38329')) # Default: QColor('#403E41')\r\n```\r\n\r\n\r\n* **Setting a custom font:**\r\n```python\r\ntooltip.setFont(QFont('Consolas', 10)) # Default: QFont('Arial', 9, QFont.Weight.Bold)\r\n```\r\n\r\n\r\n* **Applying margins to the content of the tooltip:**\r\n```python\r\ntooltip.setMargins(QMargins(10, 8, 10, 8)) # Default: QMargins(12, 8, 12, 7)\r\n```\r\n\r\n\r\n* **Setting a maximum width:**\r\n```python\r\ntooltip.setMaximumWidth(150) # Default: 16777215 (QWIDGETSIZE_MAX)\r\n```\r\n\r\n\r\n* **Enabling or disabling text centering for wrapped text:**\r\n```python\r\ntooltip.setTextCenteringEnabled(False) # Default: True\r\n```\r\n\r\n\r\n* **Enabling or disabling the drop shadow:**\r\n```python\r\ntooltip.setDropShadowEnabled(False) # Default: True\r\n```\r\n\r\n\r\n* **Changing the drop shadow strength:**\r\n```python\r\ntooltip.setDropShadowStrength(3.5) # Default: 2.0\r\n```\r\n\r\n\r\n* **Making the tooltip translucent:**\r\n```python\r\ntooltip.setOpacity(0.8) # Default: 1.0\r\n```\r\n\r\n\r\n**<br>Other customization options:**\r\n\r\n| Option | Description | Default |\r\n|-----------------------------|---------------------------------------------------------------|----------------------------|\r\n| `setShowingOnDisabled()` | Whether the tooltips should also be shown on disabled widgets | `False` |\r\n| `setFadeInEasingCurve()` | The easing curve of the fade in animation | `QEasingCurve.Type.Linear` |\r\n| `setFadeOutEasingCurve()` | The easing curve of the fade out animation | `QEasingCurve.Type.Linear` |\r\n| `setMarginLeft()` | Set left margin individually | `12` |\r\n| `setMarginRight()` | Set right margin individually | `12` |\r\n| `setMarginTop()` | Set top margin individually | `8` |\r\n| `setMarginBottom()` | Set bottom margin individually | `7` |\r\n\r\n\r\n## Demo\r\n\r\nhttps://github.com/user-attachments/assets/fa768d30-f3cc-4883-aa8b-fed3a8824b23\r\n\r\nThe demos for PyQt5, PyQt6, and PySide6 can be found in the [demo](https://github.com/niklashenning/pyqttooltip/blob/master/demo) folder.\r\n\r\n> To keep the demo simple, only the most important features are included.\r\n> To get an overview of all the customization options, check out the documentation above.\r\n\r\n\r\n## Tests\r\nInstalling the required test dependencies [PyQt6](https://pypi.org/project/PyQt6/), [pytest](https://github.com/pytest-dev/pytest), and [coveragepy](https://github.com/nedbat/coveragepy):\r\n```\r\npip install PyQt6 pytest coverage\r\n```\r\n\r\nTo run the tests with coverage, clone this repository, go into the main directory and run:\r\n```\r\ncoverage run -m pytest\r\ncoverage report --ignore-errors -m\r\n```\r\n\r\n## License\r\nThis software is licensed under the [MIT license](https://github.com/niklashenning/pyqttooltip/blob/master/LICENSE).\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A modern and fully customizable tooltip library for PyQt and PySide",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/niklashenning/pyqttooltip"
},
"split_keywords": [
"python",
" pyqt",
" qt",
" tooltip",
" modern"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5145627fbd7a6dddf3a55010607e7fb354755b9ae792991a8e66a588f6dfa2a0",
"md5": "3ba029f0be4c1396900abb4ca816a1e1",
"sha256": "a2d81b0544baea3cb8f171d908c5976125322de7721a634e5bd5f9d713bb442f"
},
"downloads": -1,
"filename": "pyqttooltip-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3ba029f0be4c1396900abb4ca816a1e1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 15356,
"upload_time": "2024-09-17T08:57:49",
"upload_time_iso_8601": "2024-09-17T08:57:49.774210Z",
"url": "https://files.pythonhosted.org/packages/51/45/627fbd7a6dddf3a55010607e7fb354755b9ae792991a8e66a588f6dfa2a0/pyqttooltip-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "562d1db43cbe060c520de42b031eacad4828946c47d63b58fa75dac629b4ac41",
"md5": "16c2eb24314df1ee385960bb50312e25",
"sha256": "4f6056c3c8d53a9873b3337905d669ba5632729ace8935d55d45fec2614a9f01"
},
"downloads": -1,
"filename": "pyqttooltip-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "16c2eb24314df1ee385960bb50312e25",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 15822,
"upload_time": "2024-09-17T08:57:51",
"upload_time_iso_8601": "2024-09-17T08:57:51.405812Z",
"url": "https://files.pythonhosted.org/packages/56/2d/1db43cbe060c520de42b031eacad4828946c47d63b58fa75dac629b4ac41/pyqttooltip-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-17 08:57:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "niklashenning",
"github_project": "pyqttooltip",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"requirements": [],
"lcname": "pyqttooltip"
}