Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yjg30737/pyqt-svg-label
PyQt QLabel which supports SVG icon
https://github.com/yjg30737/pyqt-svg-label
pyqt pyqt-examples pyqt5 pyqt5-examples pyqt5-tutorial python python3 python37 qlabel qpainter qsvgrenderer qt
Last synced: about 1 month ago
JSON representation
PyQt QLabel which supports SVG icon
- Host: GitHub
- URL: https://github.com/yjg30737/pyqt-svg-label
- Owner: yjg30737
- License: mit
- Created: 2022-02-13T08:00:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-04T01:25:17.000Z (over 1 year ago)
- Last Synced: 2024-04-29T19:06:47.355Z (10 months ago)
- Topics: pyqt, pyqt-examples, pyqt5, pyqt5-examples, pyqt5-tutorial, python, python3, python37, qlabel, qpainter, qsvgrenderer, qt
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyqt-svg-label
PyQt QLabel which supports SVG iconThis is useful to set svg icon.
If you want to use button which supports SVG icon, see pyqt-svg-icon-pushbutton.
## Requirements
* PyQt5 >= 5.8## Setup
`python -m pip install pyqt-svg-label`## Usage
* `setSvgFile(filename: str)` to set svg file.## Example
Code Sample
```python
from PyQt5.QtWidgets import QLabel, QHBoxLayout, QApplication, QWidget
from pyqt_svg_label import SvgLabelclass IconTitleWidget(QWidget):
def __init__(self):
super().__init__()
self.__initUi()def __initUi(self):
iconLbl = SvgLabel()
iconLbl.setSvgFile('ico/dark-notepad.svg')titleLbl = QLabel()
titleLbl.setText('Dark Notepad')
# get the point size of the titleLbl's font
title_lbl_size = titleLbl.font().pointSize()# to match the iconLbl's size with titleLbl's font size (usually double size is appropriate)
iconLbl.setFixedSize(title_lbl_size * 2, title_lbl_size * 2)lay = QHBoxLayout()
lay.addWidget(iconLbl)
lay.addWidget(titleLbl)self.setLayout(lay)
if __name__ == "__main__":
import sysapp = QApplication(sys.argv)
ex = IconTitleWidget()
ex.show()
sys.exit(app.exec_())
```Result
![image](https://user-images.githubusercontent.com/55078043/153744599-c563f628-de57-48b1-941c-5b5f3fe4621c.png)
If `iconLbl.setFixedSize(title_lbl_size * 2, title_lbl_size * 2)` is not included in the code sample, size of svg icon will be adjusted to fit the size of the window.
## See Also
* pyqt-svg-icon-text-widget