如何设置一个Python Qt4 window图标?

How to set a Python Qt4 window icon?

我尝试使用一个图标来自:

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

但它没有出现在 window:

#! /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)

documentation

By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName().
This function was introduced in Qt 4.6.

由于您无论如何都需要收集一个主题来与应用程序一起发布,您也可以只选择收集一些图标并直接指定文件。

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