5

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:

layer properties 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:

  1. 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.
  2. 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?

Taras
35.8k5 gold badges77 silver badges152 bronze badges
asked Mar 11 at 9:55
2
  • 2
    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/… Commented Mar 11 at 10:14
  • 2
    Unfortunately, it won't be the perfect solution I’m looking for. It opens the layer properties dialog, but not the one I need for my plugin – I've added a picture to clarify which dialog I don't need. And even when the layer isn't added to the legend, it still freezes QGIS for a while if the layer has a lot of features. However, if there is no other way to open the dialog I want, I'll use the solution you mentioned. I wasn't aware of the addToLegend argument, thanks for the tip. Commented Mar 11 at 12:24

1 Answer 1

1

When you have highlighted element in Browser panel you can open "Layer Properties" dialog using:

browser = iface.mainWindow().findChild(QDockWidget, 'Browser')
browser.showProperties()
answered Mar 21 at 19:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.