I'm building a plugin that lists layers from the database (yes, I need this workaround). When right-clicking on a listed layer, I want an action that opens the layer properties dialog.
This dialog:
Not the dialog with layer properties that can be opened when right-clicking on a layer placed in Layers Panel (tree view)!
Not this dialog:
layer properties dialog with red x sign
The solution using iface.actionLayerProperties().trigger()
is not suitable for me because in this scenario:
- I need to add a layer to the tree view, which I want to avoid as it can cause QGIS to freeze when the layer has a lot of features.
- It opens the default, extensive layer properties window with all the tabs like Information, Source, Labels, etc., which is not what I need.
Another solution using the showLayerProperties()
method from this question is also not suitable for my case because it still requires adding the layer to the interface, which I want to avoid.
I've found another solution, but it's still not what I want because it opens the layer properties dialog, which I don't need (as mentioned in point 2 above).
dlg = QgsVectorLayerProperties(iface.mapCanvas(), iface.messageBar(), vlayer)
dlg.exec_()
So maybe my question is more like this: Is there a PyQGIS method that opens the Layer Properties dialog shown in the screen above, or do I need to create this dialog from scratch using some qgis.gui
classes? If so, which ones?
1 Answer 1
When you have highlighted element in Browser panel you can open "Layer Properties" dialog using:
browser = iface.mainWindow().findChild(QDockWidget, 'Browser')
browser.showProperties()
Explore related questions
See similar questions with these tags.
showLayerProperties()
seems to fit your purpose besides the fact that it adds it to the interface. It is possible to add a layer to the interface but not show that it is there. Would that be a solution?addToLegend=False
in qgis.org/pyqgis/master/core/…