User Tools

Site Tools


qt:mainwindow-buildicon

This is an old revision of the document!


/**
 * Append a regularly defined set of differently sized icon images to a QIcon.
 * Example:
 * Assumes the resources ":myIcons/16x16/exit.png", ":myIcons/24x24/exit.png", and ":myIcons/32x32/exit.png" are available.
 *    QList<int> sizes; sizes << 16 << 24 << 32;
 *    QIcon exitIcon;
 *    buildIcon(&exitIcon, ":myIcons/%size%/exit.png", sizes);
 * buildIcon() does NOT check whether the referenced resources actually exist.
 *
 * @param theIcon pointer to the icon that will be built/appened to
 * @param iconRscTemplate a tag-based template string for the icon resource. Two tags are recognized in iconRscTemplate: %size and %dim%. When the iconRscTemplate is expanded, the tag %dim% will be replaced by {iconSize} and %size% will be replaced by {iconSize}x{iconSize}, where {iconSize} is a string cast of an element in sizeList.
 * @param sizeList contains a list of single-dimension sizes to be added to the icon.
 * @return void
 */
void MainWindow::buildIcon(QIcon* const theIcon, QString const &iconRscTemplate, QList const &sizeList)
{
    foreach (const int iconSize in sizeList)
    {
        QString theResource = iconRscTemplate;
        theResource.replace(QString("%size%"), iconSize+"x"+iconSize);  // does this work?
        theResource.replace(QString("%dim%"), iconSize+"");             // does this work?
 
        theIcon->addFile(theResource, QSize(iconSize, iconSize))
    }
}
/**
 * Append a regularly defined set of differently sized icon images to a QIcon.
 * Example:
 * Assumes the resources ":myIcons/16x16/exit.png", ":myIcons/24x24/exit.png", and ":myIcons/32x32/exit.png" are available.
 *    QList<int> sizes; sizes << 16 << 24 << 32;
 *    QIcon exitIcon;
 *    buildIcon(&exitIcon, ":myIcons/%size%/exit.png", sizes);
 * buildIcon() does NOT check whether the referenced resources actually exist.
 */
void MainWindow::buildIcon(QIcon* const theIcon,          ///< Pointer to the icon that will be built/appened to
                          QString const &iconRscTemplate, ///< A tag-based template string for the icon resource. Two tags are recognized in iconRscTemplate: %size and %dim%. When the iconRscTemplate is expanded, the tag %dim% will be replaced by {iconSize} and %size% will be replaced by {iconSize}x{iconSize}, where {iconSize} is a string cast of an element in sizeList.
                          QList const &sizeList)          ///< A list of single-dimension sizes to be added to the icon
{
    foreach (const int iconSize in sizeList)
    {
        QString theResource = iconRscTemplate;
        theResource.replace(QString("%size%"), iconSize+"x"+iconSize);  // does this work?
        theResource.replace(QString("%dim%"), iconSize+"");             // does this work?
 
        theIcon->addFile(theResource, QSize(iconSize, iconSize))
    }
}
qt/mainwindow-buildicon.1305212693.txt.gz · Last modified: 2011/05/12 15:04 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki