I created the simple frame .UI file, compiled with pyuic4, and tried the ShapeViewer.py to load the shapefile "world_borders.shp". However, the map doesn't display at the first time. I have to click out the window to make it appear. After everything works! I am working in Windows 7. Instalation "osgeo4w-setup-x86". Qgis 2.2.0-Valmiera
Why does QgsMapCanvas in Qgis 2.2.0-Valmiera only appear after losing focus?
Here is my code:
class ShapeViewer(QMainWindow, Ui_MainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.canvas = QgsMapCanvas()
self.canvas.useImageToRender(False)
self.layout = QVBoxLayout(self.frame)
self.layout.addWidget(self.canvas)
file = QFileDialog.getOpenFileName(self,"Open", ".", "Shp(*.shp)")
layer = QgsVectorLayer(file, "My Shape", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(layer);
self.canvas.setExtent(layer.extent())
cl = QgsMapCanvasLayer(layer)
self.canvas.setLayerSet([cl])
self.show()
def main(argv):
# create Qt application
app = QApplication(argv)
# Initialize qgis libraries
QgsApplication.setPrefixPath(qgis_prefix, True)
QgsApplication.initQgis()
# create main window
wnd = ShapeViewer()
wnd.show()
# run!
retval = app.exec_()
# exit
QgsApplication.exitQgis()
sys.exit(retval)
if __name__ == "__main__":
main(sys.argv)