[心得] Qt Themed Icon
最近在研究如何使用Qt themed icons。
QIcon Class Reference有些參考資訊,
但有些methods使用寫得不是很明確。
使用themed icons的好處在於它有一致的命名格式[1],
所以要換個icon theme,只要替換掉index.theme與icon sets,
Qt原始碼幾乎不用什麼更動
(甚至你可以run-time切換icon theme,就不必重新compile)
就可以輕鬆切換icon theme。
這邊以Tango icon library[2] + Qt Creator 1.3.1 (under Win 7)為例,
下載tango-icon-theme-0.8.90.tar.gz解壓後,
把source root下的index.theme.in改成index.theme。
然後把index.theme與scalable(建議使用的icon set),
複製到與你Qt program同目錄下的icons目錄,如:
xxx/debug/xxx.exe
xxx/debug/icons
xxx/debug/icons/index.theme
xxx/debug/icons/scalable
然後執行:
QIcon::setThemeName("tango");
(我是在MainWindow的constructor執行這個method。)
然後就可以依[1]去叫icon來用:),如:
foo.setIcon(QIcon::fromTheme("document-open"));
如果後來想換icon theme,就把index.theme與icon set換掉就好。
至於setThemeName要設什麼,其實我發現隨便亂設字串(除了空字串),
formTheme也抓得到 XD 似乎只要抓得到index.theme就行了。
[1]
http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
[2] http://tango.freedesktop.org/Tango_Icon_Library
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.221.79
※ 編輯: zxvc 來自: 140.115.221.79 (04/01 10:47)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章