I'm working on project where I need insert QGIS canvas as a widget in QGIS plugin. When user click on button it should be loaded into widget. Something like this, this is example where satellite map should be loaded in widget: enter image description here

How to implement this in python code?

closed as off-topic by PolyGeo Sep 10 at 12:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


In QT designer you need make right click on the widget and select "promote to", and write the class and header as seen in the image.

enter image description here

after you need compile the .ui.

In the class that loads this ui, to load some layer for example (this canvas have a objectname "canvas")

def __init__(self):
    """ Contructor """
    # Load layers
    self.airports = QgsVectorLayer(r"C:\Users\fran\Downloads\qgis_sample_data\qgis_sample_data\shapefiles\airports.shp", " airports ", "ogr")
    # Extra : set pan tool in this canvas
    self.tool = QgsMapToolPan(self.canvas)


enter image description here

  • what about raster layer? Is it the same way? – Ivan May 10 at 12:08
  • Nope, you need use QgsRasterLayer – Fran Raga May 10 at 12:18
  • Is it possible to implement it in plugin that is already done. – Ivan May 10 at 12:29
  • UI file is compiled and all the logic is done. Now I only need to add canvas widget – Ivan May 10 at 12:32
  • for load raster you have this gis.stackexchange.com/questions/144058/… – Fran Raga May 10 at 12:47

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