On Sun, 29 May 2022 at 16:31, ivan tkachenko <m...@ratijas.tk> wrote:
> Hi, > > I have a problem which sounds like it should be something trivial. > > I got a QIcon icon, aquired from a model by a delegate. How do i use it in > controls with all these icon.name [string], icon.source [url] groupped > properties or even with just an Image type? > > All sane attempts failed. I'm left with this a decade-old StackOverflow > answer > to use custom Image Provider. Sounds like too much work for something that > should be just here, out of the box? > A QIcon is a collection of images. A QQuickIcon is just a struct containing a URL plus some options (width, height, etc.). Internally to render the icon, the QQuickIcon's URL is just forwarded to a QQuickIconImage which will attempt to retrieve the image from the URL. So there is no easy way to feed a QIcon to a QQuickIcon as you must use a URL at some point. The standard solution is to use a QQuickImageProvider. In C++ you would implement your own QQuickImageProvider which will contain the QIcons. In QML then you would use a url like "image://myprovider/icon_id". Then the QML engine will call your QQuickImageProvider to retrieve the icon image. An alternative solution might be to use data urls, but I have never tried it. BR Benjamin
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest