I have two different QDockWidgets: One containing some buttons above another main_widget (File explorer), and another containing a QTabWidget.
Question: I aim to get the main_widget and the content of the tabs to the same height. How do I do this best?
Here's the basic layout:
# File explorer
file_dock = QDockWidget()
tools_layout = QHBoxLayout()
tools_layout.addWidget(QToolButton(...))
...
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addLayout(tools_layout)
layout.addWidget(main_widget)
file_dock.setLayout(layout)
# Editor
editor_dock = QDockWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
editortabs = QTabWidget()
...
layout.addWidget(editortabs)
Preliminary solution:
I can manually tune the spacing between the tools_layout
and the main_widget
:
layout.setSpacing(2)
However this setting is OS- and Style-dependent.
Is there a way to calculate the required spacing?
So far, I've found sizeHint()
, minimumSize()
and totalMinimumSize()
for the tools_layout
. In a test, they were the same. Which one to use?
That's half of the required information. How do I determine the height of the tabs? Here I've dug into QStyle.pixelMetric()
, trying
style = qapplication().style()
style.pixelMetric(QStyle.PM_TabBarHSpace)
# ! crashes the program