我无法显示从当前图标主题中选择的 QAction 图标。我用 Qt 设计器制作了 ui 并用pyuic4 sample.ui > sample.py
. 使用 设置主题中的图标后self.actionSample.setIcon(QtGui.QIcon.fromTheme(_fromUtf8("document-open")))
,我得到以下源代码:
from PyQt4 import QtCore, QtGui
import sys
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.toolBar = QtGui.QToolBar(MainWindow)
self.toolBar.setObjectName(_fromUtf8("toolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.actionSample = QtGui.QAction(MainWindow)
self.actionSample.setObjectName(_fromUtf8("actionSample"))
self.actionSample.setIcon(QtGui.QIcon.fromTheme(_fromUtf8("document-open")))
self.toolBar.addAction(self.actionSample)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(window)
window.show()
app.exec_()
当我执行它时,工具栏不显示“文档打开”图标。这是一个错误还是我做错了什么?
谢谢