I am working on a plugin 'Stripchartdrawer' current commit https://github.com/sickel/qgisstripchart/tree/ba3afd7184e33331b5af38111e91dbb9b6a2d1c0.

One of the features in this plugin is to be able to visually select features in a layer based on the value of a field by clicking or dragging in the chart. There are two cases when this kind of selection does not work. One is if the layer does not have a unique id field, if so, I am able to give a warning.

The other case is if the layer is not activated, i.e. checked in the layer panel, I would like to give a warning in that case as well if it seems as the user tries to select data, but how can I find out if the layer is activated?

In my mousereleaseevent I am doing


Where selectedids is one or more ids that I am to select.

What I want to achieve is something like (pseudocode:)

if self.layer.isActive():

But what is the real "isActive()"?

I am not 100% sure about the nomenclature here. a layer can be not visible either because it is not checked in the layer panel, if the view is outside the extent of the layer or if the layer is covered with another layer, one layer at a time can be activated, ie eg being the layer "Select features by plygon" will operate on. I want to be able to check if a layer is checked (no pun intended) and do not care if it is activated as described above.

  • For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. – PolyGeo Nov 7 at 22:22
  • 1
    You could check if the node itself is checked using if QgsProject.instance().layerTreeRoot().findLayer(QgsProject.instance().mapLayersByName( self.layer.name() )[0].id()).isVisible():; #Do something – Joseph Nov 8 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.