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
qt:mainwindow-buildicon [2011/05/12 13:19] mithatqt:mainwindow-buildicon [2011/05/13 12:32] (current) mithat
Line 1: Line 1:
 +Something like this:
  
-Append a regularly defined set of differently sized icon images to a QIcon. +<code cpp-qt MainWindow::buildIcon> 
- +/** 
-theIcon is a pointer to the icon that will be built/appened to. + * @brief Append a regularly defined set of sized icon images to a QIcon. 
-iconRscTemplate is a string that provides a template for the icon resource. The tag %size% will be replaced by "{iconSize}x{iconSize}", and %dim% by "{iconSize}" where {iconSize} is a string version of an element in sizeList. + * 
-sizeList contains a list of single-dimension sizes to be added to the icon. + The following usage example assumes the resources ":myIcons/16x16/exit.png", 
- + * ":myIcons/24x24/exit.png", and ":myIcons/32x32/exit.pngare available and 
-Example: + * that we want to bundle them together into exitIcon
-Assuming the resources :myIcons/16x16/exit.png, :myIcons/24x24/exit.png, and :myIcons/32x32/exit.png are available. + 
-<code cpp-qt> + * \code 
-QList<int> sizes; sizes << 16 << 24 << 32; + *   QList<int> sizes; sizes << 16 << 24 << 32; 
- + *   QIcon exitIcon; 
-QIcon exitIcon; + *   buildIcon(&exitIcon, ":myIcons/%size%/exit.png", sizes); 
-buildIcon(&exitIcon, ":myIcons/%size%/exit.png", sizes); + * \endcode 
- + * 
-</code> + * Does NOT check whether the referenced resources actually exist. 
-buildIcon() does NOT check whether the referenced resources actually exist. + * 
- + * @param theIcon Pointer to the icon that will be built/appened to. 
-<code cpp-qt> + * @param iconRscTemplate A tag-based template string for the icon resource. 
-void MainWindow::buildIcon(QIcon* const theIcon, QString const &iconRscTemplate, QList const &sizeList)+                        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 A list of single-dimension sizes to be added to the icon. 
 + * 
 + * @return void 
 + */ 
 +void MainWindow::buildIcon(QIcon* const theIcon, 
 +                           QString const &iconRscTemplate, 
 +                           QList<int> const &sizeList)
 { {
-    foreach (const int iconSize in sizeList)+    foreach (const int iconSizesizeList)
     {     {
         QString theResource = iconRscTemplate;         QString theResource = iconRscTemplate;
-        theResource.replace(QString("%size%"), iconSize+"x"+iconSize);+        QString dim; dim.setNum(iconSize); 
 +        theResource.replace(QString("%dim%"), dim); 
 +        theResource.replace(QString("%size%"), dim +"x"+dim);
  
-        theIcon->addFile(theResource, QSize(iconSize, iconSize))+        theIcon->addFile(theResource, QSize(iconSize, iconSize));
     }     }
 }</code> }</code>
qt/mainwindow-buildicon.1305206377.txt.gz · Last modified: 2011/05/12 13:19 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki