2017-05-24 45 views
0

我試圖用一個圖標來自:如何設置一個Python Qt4窗口圖標?

  1. https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
  2. PyQt4 set windows taskbar icon

但它並不會在窗口上顯示:

enter image description here

#! /usr/bin/env python 
# -*- coding: utf-8 -*- 
# 
import sys 
from PyQt4.QtGui import * 

# Create an PyQT4 application object. 
a = QApplication(sys.argv) 

# The QWidget widget is the base class of all user interface objects in PyQt4. 
w = QWidget() 

# Set window size. 
w.resize(820, 240) 

# Set window title 
w.setWindowTitle("Hello World!") 

# https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html 
undoicon = QIcon.fromTheme("camera-web") 
w.setWindowIcon(undoicon) 

# Show window 
w.show() 

sys.exit(a.exec_()) 

我上午在Windows 10:

  1. 蟒蛇conda --version - >conda 4.3.18
  2. Python的python --version - >Python 2.7.13 :: Anaconda custom (32-bit)

回答

1

documentation

默認情況下,只有X11將支持主題的圖標。爲了在Mac和Windows上使用主題圖標,您必須在您的themeSearchPaths()之一中綁定兼容主題並設置相應的themeName()。
此功能是在Qt 4.6中引入的。

由於您需要收集主題以隨應用程序發貨,因此您也可以選擇收集一些圖標並直接指定文件。

w.setWindowIcon(QtGui.QIcon("folder.png")) 
+0

如何捆綁兼容主題? – user

+0

我不知道,但很明顯,你沒有這樣做。 ;-) – ImportanceOfBeingErnest

+1

問題https://stackoverflow.com/questions/29392213/what-path-to-enter-in-pyqt-qicon-setthemesearchpaths-in-pyqt-on-win7似乎有幫助。 – user