<div style="color:;font: 10pt Helvetica Neue;">Ac<span style="font-family: Arial, Helvetica, sans-serif;">tually, I was able to make it work. I was including the startup.py file in the wrong directory. The code as mentioned in my last email does work and makes "show feature count" become enabled by default - but with a catch: only for layers added individually. If one adds multiple layers at once, or generates multiple layers at once, then only the first added/generated gets "show feature count" automatically enabled.</span>
<div><span style="font-family: Arial, Helvetica, sans-serif;"><br>
</span></div>

<div><span style="font-family: Arial, Helvetica, sans-serif;">Does anyone have any suggestions on how to update that code to make it work for multiple addition of layers?</span></div>

<div><span style="font-family: Arial, Helvetica, sans-serif;"><br>
</span></div>

<div><span style="font-family: Arial, Helvetica, sans-serif;">Ann<br>
</span>
<div><br>
<br>

<div style="font-family:arial,helvetica;font-size:10pt;color:black">
<div class="aolmail_wmstd_quote">
<div>-----Original Message-----<br>
From: Ann Tulliani <anntulliani@aol.com><br>
To: bernd.vogelgesang@gmx.de <bernd.vogelgesang@gmx.de>; qgis-user@lists.osgeo.org <qgis-user@lists.osgeo.org><br>
Sent: Wed, Feb 3, 2021 11:19 pm<br>
Subject: Re: [Qgis-user] Display number of features present in layer's Attribute Table<br>
<br>

<div id="yiv2036505538">
<div>
<div style="font:10pt Helvetica Neue;">Hi <span style="font-family:Arial, Helvetica, sans-serif;">Bernd,</span>

<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;">Thanks for your reply and sorry for not being clear enough. Of course, I know that I can see the number of features when I open an attribute table or by choosing "show feature count" individually for each layer. What I want to accomplish is something slightly different, but never mind, let's focus on what matters most: the most important is that I want feature count to be automatically enabled for all layers instead of me having to manually do that for dozens and dozens of layers every day.</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;">It seems that there was a feature request put up for this around 8 years ago: </span><span style="background-color:transparent;"><span style="font-family:Arial, Helvetica, sans-serif;">https://github.com/qgis/QGIS/issues/16671 and it entered this closed milestone list (but was, afaik, never implemented) almost 3 years ago: </span></span><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;">https://github.com/qgis/QGIS/milestone/52. </span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;">The one proposed workaround I found online is </span><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;">https://gis.stackexchange.com/questions/318190/setting-qgis-to-show-feature-count-always-when-layer-is-loaded. Following it, inside my </span><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;">/home/tulliani/.qgis2/python/</span><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;">startup.py I have</span><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;font-size:10pt;">:</span></div>



<div><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="background-color:transparent;font-family:Arial, Helvetica, sans-serif;">
</span>
<div style="">from qgis.core import QgsMapLayer, QgsProject</div>



<div style=""><br clear="none">
</div>



<div style="">def showFeatureCount(layers):</div>



<div style="">    layer = layers[0]</div>



<div style="">    if layer.type() == QgsMapLayer.VectorLayer:</div>



<div style="">        root = QgsProject.instance().layerTreeRoot()</div>



<div style="">        myLayerNode = root.findLayer(layer.id())</div>



<div style="">        myLayerNode.setCustomProperty("showFeatureCount", True)</div>



<div style=""><br clear="none">
</div>



<div style="">QgsProject.instance().legendLayersAdded.connect(showFeatureCount)</div>



<div style=""><br clear="none">
</div>



<div style=""><br clear="none">
</div>

</div>



<div><span style="font-family:Arial, Helvetica, sans-serif;">However, that does not see to work: it does not turn "show feature count" automatically on for all added layers.</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;">Would you or anyone else know of an alternative to the above code that would give me the desired behaviour?</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;">Thanks!</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;">Ann Turlliani</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div><span style="font-family:Arial, Helvetica, sans-serif;"><br clear="none">
</span></div>



<div class="yiv2036505538yqt0427741254" id="yiv2036505538yqt44531">
<div><br clear="none">


<div style="font-family:arial, helvetica;font-size:10pt;color:black;">

<div class="yiv2036505538">

<div>-----Original Message-----<br clear="none">
From: Bernd Vogelgesang <bernd.vogelgesang@gmx.de><br clear="none">
To: Ann Tulliani <anntulliani@aol.com>; qgis-user@lists.osgeo.org <qgis-user@lists.osgeo.org><br clear="none">
Sent: Wed, Feb 3, 2021 9:45 pm<br clear="none">
Subject: Re: [Qgis-user] Display number of features present in layer's Attribute Table<br clear="none">
<br clear="none">


<div id="yiv2036505538">

<div>
    

<div>Hi Ann,</div>


    

<div>actually I do not fully understand what you are looking for: When
      you open an attribute table, the number of features in this table
      is normally displayed in the the header of this table, and in case
      features are selected, the number of selected features.<br clear="none">
      Furthermore, when you right-click on a layer in the layer pannel
      and choose "show feature count", you can also have the number of
      features directly shown in the layers panel. In case you have a
      categorized style, it even shows the counts for those categories.<br clear="none">
      <br clear="none">
      So I really wonder where and for what did you look, cause for me
      it seems that the things you ask for, are right in front of your
      eyes.</div>


    

<div>Cheers,</div>


    

<div>Bernd<br clear="none">
    </div>


    

<div class="yiv2036505538yqt6000524926" id="yiv2036505538yqtfd95854">

<div class="yiv2036505538moz-cite-prefix">Am 04.02.21 um 02:29 schrieb Ann
      Tulliani:<br clear="none">
    </div>


    </div>

<blockquote type="cite">

<div class="yiv2036505538yqt6000524926" id="yiv2036505538yqtfd74559">
      <pre class="yiv2036505538moz-quote-pre">Dear list,

Is there a way to display - either at the status bar or directly within the Layers panel - the number of features present in the Attributes Table of each layer - or, at least, of the selected layer?
I have been looking for a setting or a plugin that would allow something like that for a while but could not find. Since that functionality would be a huge productivity boost for me and no solution exists already, I would also appreciate any hints that would put me in the right direction of implementing it with Python Scripts.
Best regards,

Ann Tulliani
</pre></div>


      <br clear="none">
      <fieldset class="yiv2036505538mimeAttachmentHeader"></fieldset>
      <pre class="yiv2036505538moz-quote-pre">_______________________________________________
Qgis-user mailing list
<a rel="nofollow noopener noreferrer" shape="rect" class="yiv2036505538moz-txt-link-abbreviated" ymailto="mailto:Qgis-user@lists.osgeo.org" target="_blank" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
List info: <a rel="nofollow noopener noreferrer" shape="rect" class="yiv2036505538moz-txt-link-freetext" target="_blank" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
Unsubscribe: <a rel="nofollow noopener noreferrer" shape="rect" class="yiv2036505538moz-txt-link-freetext" target="_blank" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
</pre>
<div class="yiv2036505538yqt6000524926" id="yiv2036505538yqtfd60345">
</div>



<div class="yiv2036505538yqt6000524926" id="yiv2036505538yqtfd50935">
    </div>

</blockquote>

<div class="yiv2036505538yqt6000524926" id="yiv2036505538yqtfd83330">
  </div>

</div>

</div>

</div>

</div>

</div>

</div>
</div>

</div>

</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>