https://github.com/hellorge/qtsvgiconengine
QtSvgIconEngine is Qt based program to use svg files as icons with support for animations and transitions.
https://github.com/hellorge/qtsvgiconengine
cpp qanimation qicon qt qt-svg-icons svg
Last synced: 4 months ago
JSON representation
QtSvgIconEngine is Qt based program to use svg files as icons with support for animations and transitions.
- Host: GitHub
- URL: https://github.com/hellorge/qtsvgiconengine
- Owner: Hellorge
- License: lgpl-2.1
- Created: 2024-07-24T05:37:11.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-11T23:30:15.000Z (over 1 year ago)
- Last Synced: 2025-02-01T23:41:17.629Z (over 1 year ago)
- Topics: cpp, qanimation, qicon, qt, qt-svg-icons, svg
- Language: CSS
- Homepage:
- Size: 2.35 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Demo uses the beautiful open source [ionicons](https://ionic.io/ionicons)
Merge requests are welcome, I'll only work on or add functionality I deem required while working on other projects of mine.
> [!NOTE]
> The `CMakeLists.txt` bundles all `.svg` files present in provided directory in a resource file `resources.qrc` located inside your build folder.
### Usage
```
SvgIconEngine iconEngine(, );
SvgIcon icon = iconEngine.getIcon(, <icon_name>, <options>);
// to get an icon
iconEngine.setDefaults(<options>);
// set new default options
iconEngine.setCachePolicy(CachePolicy::<policy>);
// {ALL, NONE, LRU}
// ALL: cache all, NONE: no caching, LRU: 100 QSvgRenderer instances will be cache at once
iconEngine.clearCache();
// clear QSvgRenderer cache, without cache QSvgRenderer instances are generated from svg paths for each time an icon is requested.
```
### Arguments
1. `SvgIconEngine::SvgIconEngine` SvgIconEngine constructor
- `path/to/svg/files/directory` | QString | Required
Folders path where icons are located,
- `options` | QVariantMap
Set default options for all new icons
- `policy` | CachePolicy
Set cache policy for SvgIconEngine, possible values are: `ALL`, `NONE`, `LRU`
2. `SvgIconEngine::getIcon` get an icon
- `style` | QString | Required
Folders path between `<path/to/svg/files/directory>` and svg file,
- `icon_name` | QString | Required
Svg filename without extension
- `options` | QVariantMap
Set options for required icon
### `<options>`
| QVariant | Value Type | Default Value | Ex. Value | Animates? | Use |
| -------------- | ---------- | -------------------------------------- | ----------------- | --------- | --- |
| color | QColor | QApplication::palette().text().color() | QColor(Qt::red) | Yes | Color used to fill icon |
| background | QColor | Qt::transparent | QColor(Qt::red) | Yes | Background fill for icons |
| size | QSize | QSvgRenderer.defaultSize() | QSize(64, 64) | Yes | Icon size |
| scale | qreal | 1 | 2 | Yes | Image size inside icon box |
| opacity | qreal | 1 | .5 | Yes | Icon opacity |
| border_color | QColor | QApplication::palette().text().color() | QColor(Qt::black) | Will | Color for border around icon |
| border_width | qreal | 0 | 10 | Will | Border width |
| default_colors | bool | false | true/false | No | If icon colors remain as in svg file |
### Example
An svg file at `/home/user/pictures/svgs/regular/calendar.svg`
```
path/to/svg/files/directory = "/home/user/pictures/svgs"
style = "regular"
icon_name = "calendar"
```
## License
This project is licensed under the terms of the GNU Lesser General Public License. See the [LICENSE](./LICENSE) file for details.