3

In PyQGIS 3 we can access the various toolbars via iface.webToolBar(), iface.vectorToolBar and so on returning QToolBar objects that can e.g. be shown with the QToolBar().show() method. Very convenient!

Attempting to access the snapping toolbar the same way, I had to realise that there is no method iface.snappingToolBar():

enter image description here

So my question: How to access the snapping toolbar with PyQGIS (in Order to show or hide it programmatically e.g.?)

1 Answer 1

3

Just found a way, but I still wonder why there is no convenience method:

>>> [t.objectName() for t in iface.mainWindow().findChildren(QToolBar)]
['mBrowserToolbar', 'mFileToolBar', 'mLayerToolBar', 'mDigitizeToolBar', 'mAdvancedDigitizeToolBar', 'mMapNavToolBar', 'mAttributesToolBar', 'mPluginToolBar', 'mHelpToolBar', 'mRasterToolBar', 'mLabelToolBar', 'mVectorToolBar', 'mDatabaseToolBar', 'mWebToolBar', 'mSnappingToolBar', 'mDataSourceManagerToolBar', 'mShapeDigitizeToolBar', 'mSelectionToolBar', 'mMeshToolBar', 'mAnnotationsToolBar', 'mToolbar', 'mBookmarkToolbar', '', 'mToolbar', 'mToolbar', 'mBrowserToolbar', 'Erlangen Erweiterungen', 'BBBB Erweiterungen', 'OSMDownloader', 'QuickOSM', 'processingToolbar', '', '', '']
>>> iface.mainWindow().findChild(QToolBar, 'mSnappingToolBar')
<PyQt5.QtWidgets.QToolBar object at 0x7fa433d1c1f0>
>>> iface.mainWindow().findChild(QToolBar, 'mSnappingToolBar').show()

... works for me.

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.