3

How to remove some icons (not all) on the Layers Panel dockwidget using python? Icons on the Layers Panel are :

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

I have written the code :

from PyQt4.QtGui import QDockWidget
for icon in iface.mainWindow().findChild(QDockWidget,'Layers').actions():
print icon.objectName()

with this code, nothing happen. So, I can not remove certain icon like in Name of children of toolbar in QGIS python and how to disable?

2

I couldn't find a direct way to access such buttons. It seems they were not given objectName values.

Nonetheless, an indirect way of accessing them is to go through controls in Layers Panel until getting the tool bar, which contains all buttons that you want to access:

widget = iface.mainWindow().findChild(QDockWidget,'Layers').children()[5]
toolBar = widget.children()[1]

You can access buttons in order of appearance in the GUI. First button is Open the layer styling dock. The second one is Add Group, the third one is the QWidgetAction Manage Layer Visibility and so on.

I'll give you 2 examples:

Removing Filter Legend by Map Content button:

toolBar.actions()[3].setVisible(False) # Because it's the fourth button

Removing the whole Manage Layer Visibility widget action:

toolBar.actions()[2].setVisible(False) # Because it's in third position

Note: Tested using QGIS v2.14.8

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.