I have an application with multiple stacked docks. The minimal width of the dock labels is by default determined by their text. This is limiting the minimal width of the DockArea and thus the space available for other content in the application. I have played with pyqtgraph.dockarea.Dock.DockLabel and pyqtgraph.widgets.VerticalLabel and set the minimum width to 0 whereever possible but could not see a change in behavior.
The QTabWidget has the usesScrollButtons property. Web browsers reduce the tab width independent of the tab labels and show only the initial part of the labels. Is there a way to achieve the same with docks in pyqtgraph? Below is a minimal working example showing the issue.
import sys
import pyqtgraph as pg
from pyqtgraph.dockarea import Dock,DockArea
from PyQt6.QtWidgets import QApplication,QWidget,QVBoxLayout
class Foo(QWidget): #,Ui_MainWindow
"""Contains minimal code to start, restore, initialize, and close the program.
All high level logic is provided in separate and plugins."""
def __init__(self):
super().__init__()
lay = QVBoxLayout(self)
self.mainDockArea = DockArea()
lay.addWidget(self.mainDockArea)
for i in range(10):
dock = Dock(f'long title dock {i}',size=(10,10))
self.mainDockArea.addDock(dock,'below')
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = Foo()
mainWindow.show()
sys.exit(app.exec())
Note: This issue has been mentioned by others before here
Setting the dock minimum width is not sufficient.
The dock area is quite a complex widget, it uses multiple levels of widgets and layouts, and one of them is the "container" in which dock labels are shown.
These labels are actually custom QLabels which update their minimum size on their own, so setting their minimum width is not an option.
What you can do instead is override the minimum size of the dock container: since the container might change due to the drag and drop feature, the solution is to override the containerChanged
function of the dock and change its minimum width instead. Note that setting a minimum size of 0 actually unsets the minimum size, so that value should be at least 1
.
class MyDock(Dock):
def containerChanged(self, c):
super().containerChanged(c)
if c and not c.minimumWidth():
c.setMinimumWidth(1)
class Foo(QWidget):
def __init__(self):
# ...
for i in range(10):
dock = MyDock(...)