Bug report #19674

Method theme() of QgsMapCanvas not in sync?

Added by Darius G. over 1 year ago. Updated 9 months ago.

Category:Python bindings / sipify
Affected QGIS version:3.4.3 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:27499


iface.mapCanvas().theme() refers always to an empty string while user set map themes in the QGIS GUI interactively.

In addition you can also check this:


Related issues

Related to QGIS Application - Feature request #19769: Add a variable returning the current map theme Open 2018-09-04


#1 Updated by Adam Szieberth about 1 year ago

Connects to #19769

It is weird that qgc.QgsProject.instance().mapThemeCollection() can provide the list of map themes and can emit a signal when map theme changed but can not give the current/active/actual map theme. Also I found applyTheme() overcomplicated as I would expect to give the name as a single argument and see the theme changed.

#2 Updated by Jürgen Fischer about 1 year ago

#3 Updated by Darius G. about 1 year ago

I have installed latest QGIS 3.4 and I have noticed that the bug is still not solved in this version?

#4 Updated by Giovanni Manghi about 1 year ago

  • Affected QGIS version changed from 3.2.2 to 3.4.0

#5 Updated by Darius G. about 1 year ago

Bug still in QGIS 3.4.2 not solved.

#6 Updated by Giovanni Manghi about 1 year ago

  • Affected QGIS version changed from 3.4.0 to 3.4.2
  • Category changed from Python plugins to Python bindings / sipify

#7 Updated by Darius G. 11 months ago

Bug still in QGIS 3.4.3 not solved.

#8 Updated by Giovanni Manghi 11 months ago

  • Affected QGIS version changed from 3.4.2 to 3.4.3

#9 Updated by Darius G. 10 months ago

Bug still in QGIS 3.4.4 not solved...

#10 Updated by Martin Dobias 10 months ago

The main map canvas is "special" - it does not have map theme assigned. Instead when you pick a map theme, styles of map layers are modified according to the theme's settings. The theme attribute in QgsMapCanvas is used for other map canvases where user want to follow a specific map theme which is different from the current one.

So in fact this is not a bug, but I understand there's some confusion due to the way how the implementation works.

To figure out the current map theme (and that's how the map themes menu in qgis does it) is like this:
1. get the current state using QgsMapThemeCollection::createThemeFromCurrentState( root, model ) (root and model come from QgsProject::instance())
2. go through the map themes QgsProject::instance()->mapThemeCollection()->mapThemes() and for each have a look at their content QgsProject::instance()->mapThemeCollection()->mapThemeState( name ) and compare it to the current theme's content

#11 Updated by Darius G. 10 months ago

  • Status changed from Open to Closed

Thank you very much for the feedback. I have implemented your procedure and it works.

#12 Updated by Giovanni Manghi 9 months ago

  • Resolution set to invalid

Also available in: Atom PDF