1

I've created my own plugin which also includes Standard QGIS-ToolButtons. I've been trying to add the "Merge Selected Features" (Advanced Digitize Tool Bar) enter image description here Tool into my Plugin.

How do I add it to a Plugin?

I've tried to add it the same way I'd add the "Split Parts" Tool Button:
Example:

 splitParts = self.iface.actionSplitParts()
 splitParts.setToolTip(self.tr('Split selected Object'))
 self.toolbar.addAction(splitParts) 

but there's no "actionMergeSelectedFeatures" call.

I've also tried stuff such as:

self.iface.advancedDigitizeToolBar().actionMergeFeatures()
self.iface.QToolBar('mAdvancedDigitizeToolBar').QAction('ActionMergeFeature')
self.iface.mainWindow().findChild(QAction, 'mActionMergeFeature').trigger()

and also tried a similar approach as I did with the ExportToSpreadsheet Processing Tool (https://gis.stackexchange.com/a/447931/135540)

and I also tried to work with "dissolve" instead as well (ex. processing tool native:dissolve)

but I'm not getting anywhere.

If needed, most of my code is visible in the link I posted above.

2 Answers 2

3

The action object name is 'mActionMergeFeatures'. So the following works:

self.iface.mainWindow().findChild(QAction, 'mActionMergeFeatures')

E.g.

class TestWindow(QMainWindow):
    
    def __init__(self, iface):
        self.iface = iface
        super(TestWindow, self).__init__()
        self.setGeometry(500, 500, 500, 350)
        self.toolbar = QToolBar(self)
        self.addToolBar(self.toolbar)
        self.a = self.iface.mainWindow().findChild(QAction, 'mActionMergeFeatures')
        self.toolbar.addAction(self.a)
        
dlg = TestWindow(iface)
dlg.show()

Result:

enter image description here

1
  • oh true, I tried it but I had done it wrong. I added it to the button this way now and it works: self.actionMergeLayers = QAction(QIcon(':/plugins/unterhalt/icons/mActionMergeFeature.png'), self.tr('Objekte verschmelzen')) MergeLayers = self.iface.mainWindow().findChild(QAction, 'mActionMergeFeatures') self.toolbar.addAction(MergeLayers)
    – geofreak
    Commented Jan 17, 2023 at 8:09
1

So thanks to @BenW I was able to get the solution. It was similar to what I had tried, but I had integrated it wrongly. I know integrated it directly to the button instead of separately:

self.actionMergeLayers = QAction(QIcon(':/plugins/unterhalt/icons/mActionMergeFeature.png'), self.tr('Objekte verschmelzen'))
MergeLayers = self.iface.mainWindow().findChild(QAction, 'mActionMergeFeatures')
self.toolbar.addAction(MergeLayers)

Don't even need the self.actionMergeLayers.triggered.connect() part.

Thank you very much for your help. I guess I was just thinking too complicated..

Your Answer

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

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