This working for me

layer_tree = iface.layerTreeView()

layer_tree_dock = layer_tree.parent().parent()

toolbar = layer_tree_dock.findChildren(QToolBar)[0]

def my_function():

    print("ook")

my_icon = QIcon("D:\Frequency.svg")

my_tooltip = "Description (text menu or action tooltip)"

my_action = QAction(my_icon, my_tooltip)

my_action.triggered.connect(my_function)

toolbar.addAction(my_action)

# toolbar.removeAction(my_action)

Best Regards


Il 27/04/2023 16:37, Catania, Luke A ERDC-RDE-GRL-VA CIV ha scritto:

Another user posted this solution to add an icon. I tried it, but not getting any additional icon showing up in the layer’s panel..

toolbar= iface.mainWindow().findChild(QDockWidget, "Layers").findChild(QToolBar)

Then you can just add QAction to this toolbar :

my_wonderful_action= QAction(QIcon("path/to/icon.svg"), "Description (text menu or action tooltip)")

my_wonderful_action.triggered.connect(my_awesome_processing_function)

toolbar.addAction(my_wonderful_action)

*From:* Giulio Fattori <[email protected]>
*Sent:* Thursday, April 27, 2023 7:09 AM
*To:* Nyall Dawson <[email protected]>; Catania, Luke A ERDC-RDE-GRL-VA CIV <[email protected]>
*Cc:* [email protected]
*Subject:* Re: [QGIS-Developer] Customizing Layer Panel

Great, what if I want an icon too?

Thanks in advance for any help

Giulio

Il 27/04/2023 00:06, Nyall Dawson via QGIS-Developer ha scritto:



    On Thu, 27 Apr 2023 at 07:42, Catania, Luke A ERDC-RDE-GRL-VA CIV
    via QGIS-Developer <[email protected]> wrote:
    >
    > But I am looking to access the dock widget and add two icons in
    its row of icons or maybe a menu.

    It's not available via the stable API, but let's not let that stop
    us! 😆

    layer_tree = iface.layerTreeView()
    layer_tree_dock = layer_tree.parent().parent()
    toolbar = layer_tree_dock.findChildren(QToolBar)[0]

    my_action = QAction('something')
    toolbar.addAction(my_action)

    Nyall


    >
    >
    >
    > Thanks in advance for any help,
    >
    > Luke
    >
    > _______________________________________________
    > QGIS-Developer mailing list
    > [email protected]
    > List info:
    Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked
    <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>
    > Unsubscribe:
    Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked
    <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>



    _______________________________________________

    QGIS-Developer mailing list

    [email protected]

    List info:Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked  
<Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>

    Unsubscribe:Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked 
 <Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked>

_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
  • [QGIS-Developer] QG... Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer
    • [QGIS-Develope... Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer
      • Re: [QGIS-... Nyall Dawson via QGIS-Developer
        • Re: [Q... Giulio Fattori via QGIS-Developer
          • Re... Etienne Trimaille via QGIS-Developer
          • Re... Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer
            • ... Giulio Fattori via QGIS-Developer

Reply via email to