<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Charles, thanks very much. This looks promising.</p>
<p>I'm out all day but will check it later and advise . . . . .<br>
</p>
<pre class="moz-signature" cols="72">-----
Cheers, Spring</pre>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 14/Apr/2021 07:34, Charles
Dixon-Paver wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAK2KqieNXsmPuq_BfWV=+G9JN596nEFbN2yaRy4VnpqBBV-A_w@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">If you want the layer dependant label visibility to
be applied to the entire layer, then indeed using an expression
in the "Show label" rendering option should do what you are
asking. By the sounds of things though, you should probably just
be using a simple expression like:
<div><br>
</div>
<div><span style="font-family:monospace">if (is_layer_visible(
'toggle_layer_name' ), 1, 0)</span></div>
<div><br>
</div>
<div>Invert it to only display the labels when a certain layer
is <i>not</i> visible by simply switching the true/ false
statement order, e.g. <span style="font-family:monospace">if
(is_layer_visible( 'toggle_layer_name' ),false,true)</span><br>
</div>
<div><br>
</div>
<div>If you are wanting the behaviour to be applied to a
specific rule you can specify a similar context within the
rule using an expression like <span
style="font-family:monospace">if (is_layer_visible(
'toggle_layer_name' ),{expression when true}, false)</span></div>
<div><br>
</div>
<div>Note, however, that although the map canvas will
automatically toggle the display of the visible layers, it
probably isn't going to automatically update the label
rendering... So even with these expressions working properly
you may have to refresh the map or pan a little to check that
it's working after changing the layer visibility. As I'm sure
you can imagine, labeling can be quite a computationally
expensive resource so there are likely very good reasons for
this behaviour, although you can probably work around it using
some python code or similar. An example might be the
following:</div>
<div><br>
</div>
<div><span style="font-family:monospace"><span>def</span>
redrawWhenToggled(layerTreeNode):<br>
canvas = iface.mapCanvas()<br>
canvas.redrawAllLayers()<br>
<br>
</span></div>
<div><span style="font-family:monospace">toggle_layer =
QgsProject.instance().layerTreeRoot().findLayer('toggle_layer_name_76f7c585_xxxxx')<br>
toggle_layer.visibilityChanged.connect(redrawWhenToggled)</span><br>
</div>
<div><br>
</div>
<div>That should redraw the canvas each time you toggle the
visibility on that particular layer. Note that
'toggle_layer_name_76f7c585_xxxxx' is of course the layerID.
You can easily get the layer id by selecting/ highlighting the
item in the layers tab and using <span
style="font-family:monospace">iface.activeLayer().id()</span>
in the python console.</div>
<div><br>
</div>
<div>I would probably also use a layer id, rather than a name,
in the "is_layer_visible" expression, so that the expression
continues to work even when a layer is renamed or duplicated
etc.</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, 13 Apr 2021 at 23:27,
Springfield Harrison <<a href="mailto:stellargps@gmail.com"
target="_blank" moz-do-not-send="true">stellargps@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Hello Folks, back again!<br>
</p>
<p>I'm trying to have labels display only when that "layer"
is turned on (visible). BUT my layers are actually rule
based symbology and apply only to selected records in the
layer (as per the rules), (sub-layers?).</p>
Under the Rendering tab for labels I find:
<p><i><span
style="color:rgb(64,64,64);font-family:Lato,proxima-nova,"Helvetica
Neue",Arial,sans-serif;font-size:16px;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(252,252,252);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">With
data-defined expressions in<span> </span></span></i><i><span
style="box-sizing:border-box;border:1px solid
rgb(127,187,227);background:none 0% 0% repeat scroll
rgb(127,187,227);font-size:12.8px;font-weight:700;border-radius:4px;padding:2.4px
6px;margin:auto
2px;color:rgb(64,64,64);font-family:Lato,proxima-nova,"Helvetica
Neue",Arial,sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Show
label</span></i><i><span
style="color:rgb(64,64,64);font-family:Lato,proxima-nova,"Helvetica
Neue",Arial,sans-serif;font-size:16px;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(252,252,252);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>and<span> </span></span></i><i><span
style="box-sizing:border-box;border:1px solid
rgb(127,187,227);background:none 0% 0% repeat scroll
rgb(127,187,227);font-size:12.8px;font-weight:700;border-radius:4px;padding:2.4px
6px;margin:auto
2px;color:rgb(64,64,64);font-family:Lato,proxima-nova,"Helvetica
Neue",Arial,sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">Always
Show</span></i><i><span
style="color:rgb(64,64,64);font-family:Lato,proxima-nova,"Helvetica
Neue",Arial,sans-serif;font-size:16px;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(252,252,252);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span>you
can fine tune which labels should be rendered.</span></i></p>
<p>but there is no explanation of how to implement this
feature.</p>
<p>I would expect that something like this may be in the
right direction: <br>
</p>
<p><i>if (is_layer_visible( @layer_name ) = 0, ("Tree_Tag"
|| ' - ' || ' (' || "More" || ') ') , '*')</i><br>
</p>
<p>Any thoughts on how to selectively make labels visible
would be great.<br>
</p>
<pre cols="72">-----
Cheers, Spring</pre>
<div><br>
</div>
<br>
<blockquote type="cite"> </blockquote>
</div>
_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank"
moz-do-not-send="true">Qgis-user@lists.osgeo.org</a><br>
List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-user"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-user"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
</blockquote>
</div>
</blockquote>
</body>
</html>