User Tools

Site Tools


qt:icons

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:icons [2011/05/13 16:47] – [System theme using QIcon::fromTheme()] mithatqt:icons [2011/05/13 17:01] (current) – [Creating a Qt Resource for the theme] mithat
Line 109: Line 109:
 ===== QStyle's standardIcon() function ===== ===== QStyle's standardIcon() function =====
  
-An alternative to using icon resources is provided by the ''standardIcon()'' function, which is an instance member of the ''QStyle'' abstract base class((http://doc.qt.nokia.com/4.7/qstyle.html#standardIcon)). This function provides access to the subset of standard system icons enumerated in ''StandardPixmap-enum''((http://doc.qt.nokia.com/4.7/qstyle.html#StandardPixmap-enum)).+An alternative to using icon resources is provided by the ''standardIcon()'' method, which is an instance member of the ''QStyle'' abstract base class((http://doc.qt.nokia.com/4.7/qstyle.html#standardIcon)). This method provides access to the subset of standard system icons enumerated in ''StandardPixmap-enum''((http://doc.qt.nokia.com/4.7/qstyle.html#StandardPixmap-enum)).
  
-The enumerated icons should be available on all platforms, so testing for their existence isn't required. The main issue with using ''standardIcon()'' is that on my platform at least (Linux, Ubuntu 10.10) it does not provide multi-sized icons. You'll get icons from the system theme, but they will be resized and fuzzy at times. (I haven't tested the behavior on Windows and OS X, so it might not be the case on those platforms.) Another issue is that many common icons are not part of ''StandardPixmap-enum''.+The main issue with using ''standardIcon()'' is that on my platform at least (Linux, Ubuntu 10.10) it does not provide multi-sized icons. You'll get icons from the system theme, but they will be resized and fuzzy at times. (I haven't tested the behavior on Windows and OS X, so it might not be the case on those platforms.) Another issue is that many common icons are not part of ''StandardPixmap-enum''.
  
 Implementation requires only a bit of straight-forward hand-coding. Implementation requires only a bit of straight-forward hand-coding.
Line 199: Line 199:
  
 ==== Caveat ==== ==== Caveat ====
-QIcon's determination of the system icon theme is at the time of this writing not reliable under Linux -- at least not under Openbox; GNOME and Xfce are yet to be tested. A possible workaround is to use as yet undefined ''HeroicMeasures()''™ to suss out the actual icon theme and then set it((http://doc.qt.nokia.com/4.7/qicon.html#setThemeName, http://doc.qt.nokia.com/4.7/qicon.html#themeName)) in the constructor:+QIcon's determination of the system icon theme is at the time of this writing not reliable under Linux -- at least not under Xfce, Openbox, Fluxbox, and IceWM; GNOME seems to work as expected((http://bugreports.qt.nokia.com/browse/QTBUG-19268)). A possible workaround is to use as yet undefined ''HeroicMeasures()''™ to suss out the actual icon theme and then set it((http://doc.qt.nokia.com/4.7/qicon.html#setThemeName, http://doc.qt.nokia.com/4.7/qicon.html#themeName)) in the constructor:
 <code cpp-qt> <code cpp-qt>
 QString iconTheme = My::HeroicMeasures(); QString iconTheme = My::HeroicMeasures();
 QIcon::setThemeName(iconTheme);</code> QIcon::setThemeName(iconTheme);</code>
  
 +Until such ''HeroicMeasures()''™ are worked out or the bug is fixed, this method can't really be recommended.
 ===== Custom theme using  QIcon::fromTheme() ===== ===== Custom theme using  QIcon::fromTheme() =====
  
-The static function ''QIcon::fromTheme()'' used above can also be used with custom, locally defined icon themes that are placed into Qt Resource files((This idea comes from http://tkrotoff.blogspot.com/2010/02/qiconfromtheme-under-windows.html)). To accomplish this we need to do three things: Create a custom icon theme, create a Qt Resource with the theme, and implement the code needed to use the custom theme.+The static function ''QIcon::fromTheme()'' used above can also be used with custom, locally defined icon themes that are placed into Qt Resource files((This idea comes from http://tkrotoff.blogspot.com/2010/02/qiconfromtheme-under-windows.html)). Themes defined this way can be used across all platforms. To accomplish this we need to do three things: Create a custom icon theme, create a Qt Resource with the theme, and implement the code needed to use the custom theme.
  
 To describe the process, I will use an example of a custom theme that provides icons in a variety of sizes for our example application. The icons themselves are taken from the raucously popular, public domain Tango Project((http://tango.freedesktop.org/Tango_Desktop_Project)) using files provided in Ubuntu's 10.10 tango-icon-theme package((http://packages.ubuntu.com/maverick/tango-icon-theme)). Because unlike Bill Bruford I am not good at naming things((Bruford, Bill. "Who Managed the Manager?" In //Bill Bruford: the autobiography : Yes, King Crimson, Earthworks, and more.// London: Jawbone Press, 2009. 60-72. )), I call the custom theme, "TangoMFK". To describe the process, I will use an example of a custom theme that provides icons in a variety of sizes for our example application. The icons themselves are taken from the raucously popular, public domain Tango Project((http://tango.freedesktop.org/Tango_Desktop_Project)) using files provided in Ubuntu's 10.10 tango-icon-theme package((http://packages.ubuntu.com/maverick/tango-icon-theme)). Because unlike Bill Bruford I am not good at naming things((Bruford, Bill. "Who Managed the Manager?" In //Bill Bruford: the autobiography : Yes, King Crimson, Earthworks, and more.// London: Jawbone Press, 2009. 60-72. )), I call the custom theme, "TangoMFK".
Line 268: Line 269:
 </RCC></code> </RCC></code>
  
-Once you have created the ''*.qrc'' file with the needed content, you will need to add it to your project. In Qt Creator, right-click the name of the project, select //Add Existing Files...//, and add the ''*.qrc'' file. After doing this, you can use Qt Creator's GUI-based resource manager to verify that all the icons have been correctly included.+Once you have created the ''*.qrc'' file with the required content, you will need to add it to your project. In Qt Creator, right-click the name of the project, select //Add Existing Files...//, and add the ''*.qrc'' file. After doing this, you can use Qt Creator's GUI-based resource manager to verify that all the icons have been correctly included.
  
 Note that in the set of icons I drew from, there were no 48x48 icons. To maintain best compatibility with Windows OSes, you ideally should include 48x48 icons as well((See http://msdn.microsoft.com/en-us/library/ms997636.aspx for a discussion of Windows XP icons and http://msdn.microsoft.com/en-us/library/aa511280.aspx for Windows 7.)). Note that in the set of icons I drew from, there were no 48x48 icons. To maintain best compatibility with Windows OSes, you ideally should include 48x48 icons as well((See http://msdn.microsoft.com/en-us/library/ms997636.aspx for a discussion of Windows XP icons and http://msdn.microsoft.com/en-us/library/aa511280.aspx for Windows 7.)).
  
-The pros and cons associated with this approach are essentially identical to [[#Explicitly build and bind icons at runtime]] above, but there is one important difference: you cannot combine this approach with [[#Custom theme using  QIcon::fromTheme()]] because the setting of icon themes is [[MainWindow-setActionIcon|dynamic]]: the last theme name you set is the theme with which all icons will be rendered. +The pros and cons associated with this approach are essentially identical to [[#Explicitly build and bind icons at runtime]] above. There is, however, one important difference: you cannot combine this approach with the [[#Custom theme using  QIcon::fromTheme()]] approach because the setting of icon themes is [[MainWindow-setActionIcon|dynamic]]: the last theme name you set is the theme with which all icons will be rendered. 
  
 ==== Code implementation ==== ==== Code implementation ====
qt/icons.1305305263.txt.gz · Last modified: 2011/05/13 16:47 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki