User Tools

Site Tools


qt:mainwindow-buildicon

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
qt:mainwindow-buildicon [2011/05/12 12:36] mithatqt:mainwindow-buildicon [2011/05/13 11:29] mithat
Line 1: Line 1:
-<code cpp-qt> +Something like this: 
-void MainWindow::buildIcon(QIcon const *theIcon, QString const &resourceTemplate, QList const &sizeList)+ 
 +<code cpp-qt MainWindow::buildIcon> 
 +/** 
 + * Append a regularly defined set of different sized icon images to a QIcon. 
 + * 
 + * The following usage example assumes the resources ":myIcons/16x16/exit.png", 
 + * ":myIcons/24x24/exit.png", and ":myIcons/32x32/exit.png" are available and 
 + * that we want to bundle them together into exitIcon. 
 + * 
 + * \code 
 +   QList<int> sizes; sizes << 16 << 24 << 32; 
 +   QIcon exitIcon; 
 +   buildIcon(&exitIcon, ":myIcons/%size%/exit.png", sizes); 
 + * \endcode 
 + * 
 + * Does NOT check whether the referenced resources actually exist. 
 + * 
 + * @return void 
 + */ 
 +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<int> const &sizeList      ///< A list of single-dimension sizes to be added to the icon. 
 +                          )
 { {
-    QString theResource;    // used to expand the resourceTemplate for each entry in sizeList +    foreach (const int iconSizesizeList)
-    foreach (const int iconSize in sizeList)+
     {     {
-        // replace %size% in resourceTemplate << iconSize << "x" << iconSize +        QString theResource = iconRscTemplate; 
-        // TODO +        theResource.replace(QString("%size%"), iconSize+"x"+iconSize);  // does this work? 
-        theIcon->addFile(theResource, QSize(iconSize, iconSize))+        theResource.replace(QString("%dim%"), iconSize+"");             // does this work? 
 + 
 +        theIcon->addFile(theResource, QSize(iconSize, iconSize));
     }     }
 }</code> }</code>
qt/mainwindow-buildicon.txt · Last modified: 2011/05/13 12:32 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki