I am creating a PyQT and QGIS application and im trying to add a combobox to the UI. I have defined the layout of my UI in a separate module to the main module. I know it is an issue with the combobox as this error only occurs when I add it. The application runs but when I close it this error is displayed in the terminal - QPixmap: Must construct a QApplication before a QPaintDevice
Here is the code for the UI
import sys
import os
from qgis.gui import *
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ui_mainWindow import Ui_MainWindow
class DeforestationMapWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.connect(self.actionZoomIn, SIGNAL("triggered()"), self.zoomIn)
self.connect(self.actionZoomOut, SIGNAL("triggered()"), self.zoomOut)
self.connect(self.actionPan, SIGNAL("triggered()"), self.panMode)
self.connect(self.actionAddArea, SIGNAL("triggered()"), self.addArea)
self.connect(self.actionRemoveArea, SIGNAL("triggered()"), self.removeArea)
self.connect(self.actionGetInfo, SIGNAL("triggered()"), self.getInfo)
self.cb.currentIndexChanged.connect(self.selectionchange)
#handlers for the events
def zoomIn(self):
pass
def zoomOut(self):
pass
def panMode(self):
pass
def addArea(self):
pass
def removeArea(self):
pass
def getInfo(self):
pass
def selectionchange(self,i):
print "Items in the list are :"
for count in range(self.cb.count()):
print self.cb.itemText(count)
print "Current index",i,"selection changed ",self.cb.currentText()
def main():
app = QApplication(sys.argv)
QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True)
QgsApplication.initQgis()
deforestMapWindow = DeforestationMapWindow()
deforestMapWindow.show()
deforestMapWindow.raise_()
app.exec_()
app.deleteLater()
deforestMapWindow.close()
QgsApplication.exitQgis()
if __name__ == "__main__":
main()
Here is the code for the UI
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import resources
class Ui_MainWindow(object):
def setupUi(self, window):
window.setWindowTitle("Deforestation")
self.centralWidget = QWidget(window)
self.centralWidget.setMinimumSize(900, 400)
window.setCentralWidget(self.centralWidget)
self.toolbar = QToolBar()
window.addToolBar(Qt.TopToolBarArea, self.toolbar)
buttonIcon = QIcon(":/resources/zoomIn.png")
self.actionQuit = QAction(buttonIcon, "Quit", window)
buttonIcon = QIcon(":/resources/zoomIn.png")
self.actionZoomIn = QAction(buttonIcon, "Zoom In", window)
buttonIcon = QIcon(":/resources/zoomOut.png")
self.actionZoomOut = QAction(buttonIcon, "Zoom Out", window)
buttonIcon = QIcon(":/resources/pan.png")
self.actionPan = QAction(buttonIcon, "Pan", window)
self.actionPan.setCheckable(True)
buttonIcon = QIcon(":/resources/getInfo.png")
self.actionGetInfo = QAction(buttonIcon, "Get Info", window)
self.actionGetInfo.setCheckable(True)
buttonIcon = QIcon(":/resources/draw.png")
self.actionAddArea = QAction(buttonIcon, "Draw Area", window)
buttonIcon = QIcon(":/resources/remove.png")
self.actionRemoveArea = QAction(buttonIcon, "Remove Area", window)
self.cb = QComboBox()
self.cb.insertItems(1,["One","Two","Three"])
self.toolbar.addAction(self.actionZoomIn)
self.toolbar.addAction(self.actionZoomOut)
self.toolbar.addAction(self.actionPan)
self.toolbar.addSeparator()
self.toolbar.addAction(self.actionGetInfo)
self.toolbar.addAction(self.actionAddArea)
self.toolbar.addAction(self.actionRemoveArea)
self.toolbar.addSeparator()
self.toolbar.addWidget(self.cb)
window.resize(window.sizeHint())
I am running this on OS X I would love for someone to explain what I am doing wrong and help me fix this.