1

I had done a simple standalone application that loads a shapefile and does some basic actions like zoom in, zoom out, pan etc in the viewer. In my Python file, I had set the icon path for all these (zoom in, zoom out, pan) as directory which exist in my desktop. Now, when I send the application to the user, he is unable to view the toolbar icons. The only way is to change the icon path of the target machine and run the file or is there any other way to solve this?

# Create the actions for our tools and connect each to the appropriate
    # method
    self.actionAddLayer = QAction(QIcon("....../Standalone_External_QGIS_Application/AddVectorlayer.png"), \
                                  "Add Layer", self.frame)
    self.connect(self.actionAddLayer, SIGNAL("activated()"),self.addLayer)
    self.actionZoomIn =QAction(QIcon("....../Standalone_External_QGIS_Application/Zoomin.png"), \
                               "Zoom In", self.frame)
    self.connect(self.actionZoomIn, SIGNAL("activated()"), self.zoomIn)
    self.actionZoomOut = QAction(QIcon("....../Standalone_External_QGIS_Application/Zoomout.png"), \
                                 "Zoom Out", self.frame)
    self.connect(self.actionZoomOut, SIGNAL("activated()"), self.zoomOut)
    self.actionPan = QAction(QIcon("....../Standalone_External_QGIS_Application/pan.png"), \
                             "Pan", self.frame)
    self.connect(self.actionPan, SIGNAL("activated()"), self.pan)
    self.actionExplore = QAction(QIcon("....../Standalone_External_QGIS_Application/Identity.png"), \
                                 "Explore", self.frame)
    self.connect(self.actionExplore, SIGNAL("activated()"), self.Explore)
    self.actionZoomFull = QAction(QIcon("....../Standalone_External_QGIS_Application/ZoomtoFull.png"), \
                                 "Zoom Full Extent", self.frame)
    self.connect(self.actionZoomFull, SIGNAL("activated()"), self.zoomFull)

1 Answer 1

2

The best practice is to use a resource.qrc file and compile that in into a resource_rc.py file using pyrcc4. pyrcc4 ships in the QGIS folder run OSGeo4w.bat to get access to it.

pyrcc4 -o resources_rc.py resource.qrc

In your Python code you then do:

import resources_rc
icon = QIcon("Identity.png")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.