I'm at the moment working on some QGIS Plugin and are facing a problem I couldn't find a solution for.
Basically I'm composing a map from many different layers and I want to set one layer to be shown in the Overview Panel (the one from View -> Panels -> Overview Panel).
Is there a way to set programatically which layer should be shown in the overview panel?
And does anybody know if there exists any PyQgis class, so that one can use the overview panel with it's functionality in a stand alone application?
@underdark said what I was looking for. I was all the time searching for something like "MapOverviewPanel" since it's named like this or for "overview panel" etc and had no success. Knowing it's named QgsMapOverviewCanvas (not Panel..) I found the following Link:
For completeness I'll repost the code here:
from PyQt4.QtCore import Qt, QObject
from PyQt4.QtGui import QColor, QVBoxLayout, QDockWidget
from qgis.gui import QgsMapOverviewCanvas
from qgis.utils import iface
layer = iface.activeLayer()
canvas = iface.mapCanvas()
main_window = iface.mainWindow()
new_dock_widget = QDockWidget(u"My doc widget")
layout = QVBoxLayout()
map_canvas_overview = QgsMapOverviewCanvas(
new_dock_widget,
canvas
)
layerset = [layer.id()]
map_canvas_overview.setLayerSet(layerset)
map_canvas_overview.setBackgroundColor(QColor(255, 127, 0))
map_canvas_overview.enableAntiAliasing(True)
map_canvas_overview.setMinimumWidth(380)
map_canvas_overview.setMinimumHeight(280)
new_dock_widget.resize(400, 300)
layout.addWidget(map_canvas_overview)
new_dock_widget.setLayout(layout)
main_window.addDockWidget(Qt.RightDockWidgetArea, new_dock_widget)
new_dock_widget.show()
map_canvas_overview.refresh() # Make the background color disappear?
# Layout optional playground
layout.setContentsMargins(0, 0, 0, 0)
As you can see, this script is not communicating with the existing Overview panel in the Qgis GUI but instead creating a new widget inside the canvas showing the overview there (see image below on the right).
What I would like to do for the plugin, is communicating with the existing QgsMapOverviewCanvas which the user can de-/activate from the View-Panels menu. For the standalone application this was exactly the class reference I was looking for.
How can I communicate with the Overview Panel and not create a widget with a second overview panel inside the map canvas.