I am creating a plugin for QGIS using PyQt5 and have implemented a dock widget that shows all layers. I was wondering if it was possible to add buttons to the Title Bar of the dock widget like the ones QGIS has QGIS Dock Widget Title Bar Widgets.
I looking into the documentation and I know there is a setTitleBarWidget but that sets only one widget. The other thing I tried was created a QToolBar as a child of the QDockWidget which seemed to work but not completely. Floating and Docked. I also tried setContentsMargins(0, 30, 0, 0) but that didn't work either. Playing with other values only increased/decreased the other sides but not the title margin. Any help or guidance is greatly appreciated. Thank you.
def layerTree(self):
self.layers_widget = QDockWidget('Layers', self)
self.view = QgsLayerTreeView(self.layers_widget)
self.root = QgsProject.instance().layerTreeRoot()
self.model = QgsLayerTreeModel(self.root)
self.model.setFlag(QgsLayerTreeModel.AllowNodeReorder)
self.model.setFlag(QgsLayerTreeModel.AllowNodeChangeVisibility)
self.view.setModel(self.model)
self.layers_widget.setWidget(self.view)
self.addDockWidget(Qt.LeftDockWidgetArea, self.layers_widget)
self.lt_toolbar = QToolBar(self.layers_widget)
self.delete_layer = QAction('Delete Layer')
self.lt_toolbar.addAction(self.delete_layer)