[SOLVED]QML standard icons



  • I'm looking to get some of the OS's standard images within QML, and want to know if there is a way to do this. The only way I can see how to do it is to derive off of QQuickImageProvider and provided the needed pixmap. Is there a simpler way?



  • Can you get the path of your images wanted? If yes, you can use path to set source of Image.



  • I'm trying to get the standard pixmaps from QStyle, and I don't believe those have an associated path for them. I did something like this and it works, but if there was an easier way I would like to do it.

    @
    QPixmap ZStandardImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
    {
    if(mWidgetOfInterest.isNull())
    return QPixmap(requestedSize);

    QIcon icon;
    if(id == DNTs("SP_MessageBoxWarning"))
    {
         icon = mWidgetOfInterest->style()->standardIcon(QStyle::SP_MessageBoxWarning);
    }
    
    if(icon.isNull())
        return QPixmap(requestedSize);
    
    return icon.pixmap(requestedSize);
    

    }
    @



  • No I am afraid those icons are not directly exposed to qml so the suggested workaround is probably ok.

    We do have support for iconNames on some controls though. I.e you can set iconName instead of iconSource to use bundled or system-specific themes, but that is not what you are looking for here.



  • Sweet, thanks to both.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.