我實現了一個GUI,並且圖標不顯示在GUI中。開發路徑是一個git克隆(存儲庫目錄)。如果我將路徑更改爲簡單的本地路徑,則將顯示GUI中的圖標。PyQt4:圖標不顯示在GUI中
任何想法的原因或解決這個問題?
GUI是在QtDesigner中設計的。從pyuic4
生成的GUI代碼在這裏,它是:
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(803, 502)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("icons/Server.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 803, 22))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menuFilter = QtGui.QMenu(self.menubar)
self.menuFilter.setObjectName(_fromUtf8("menuFilter"))
self.menuFile = QtGui.QMenu(self.menubar)
self.menuFile.setObjectName(_fromUtf8("menuFile"))
MainWindow.setMenuBar(self.menubar)
self.toolBar = QtGui.QToolBar(MainWindow)
self.toolBar.setObjectName(_fromUtf8("toolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.toolBar_2 = QtGui.QToolBar(MainWindow)
self.toolBar_2.setObjectName(_fromUtf8("toolBar_2"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_2)
self.actionFilter = QtGui.QAction(MainWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8("icons/Filter.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionFilter.setIcon(icon1)
self.actionFilter.setObjectName(_fromUtf8("actionFilter"))
self.actionFilter_by_Server = QtGui.QAction(MainWindow)
self.actionFilter_by_Server.setObjectName(_fromUtf8("actionFilter_by_Server"))
self.actionExit = QtGui.QAction(MainWindow)
self.actionExit.setObjectName(_fromUtf8("actionExit"))
self.menuFilter.addAction(self.actionFilter_by_Server)
self.menuFile.addAction(self.actionExit)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuFilter.menuAction())
self.toolBar.addAction(self.actionFilter)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Development Monitoring", None, QtGui.QApplication.UnicodeUTF8))
self.menuFilter.setTitle(QtGui.QApplication.translate("MainWindow", "Filter", None, QtGui.QApplication.UnicodeUTF8))
self.menuFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
self.toolBar.setWindowTitle(QtGui.QApplication.translate("MainWindow", "toolBar", None, QtGui.QApplication.UnicodeUTF8))
self.toolBar_2.setWindowTitle(QtGui.QApplication.translate("MainWindow", "toolBar_2", None, QtGui.QApplication.UnicodeUTF8))
self.actionFilter.setText(QtGui.QApplication.translate("MainWindow", "Filter", None, QtGui.QApplication.UnicodeUTF8))
self.actionFilter.setStatusTip(QtGui.QApplication.translate("MainWindow", "Filter", None, QtGui.QApplication.UnicodeUTF8))
self.actionFilter.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+F", None, QtGui.QApplication.UnicodeUTF8))
self.actionFilter_by_Server.setText(QtGui.QApplication.translate("MainWindow", "Filter by Server", None, QtGui.QApplication.UnicodeUTF8))
self.actionExit.setText(QtGui.QApplication.translate("MainWindow", "Exit", None, QtGui.QApplication.UnicodeUTF8))
顯示GUI中的代碼是在這裏提前
class MainWindow(QtGui.QMainWindow):
def __init__(self, app, parent= None):
log.trace()
QtGui.QWidget.__init__(self,parent)
self.app=app
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
感謝。
克里斯
Sry我添加了代碼 – Chris
這似乎是一個文件系統問題。你是從目錄內運行應用程序到圖標/相對的地方嗎?你的開發路徑是什麼樣子,你在哪裏啓動應用程序?另外不要忘記,你實際上需要__init__一個QMainWindow而不是一個QWidget – jdi