I'm working with a PySide2 application and encountering an issue where there's unexpected extra space around my QTabWidget
within a QMainWindow
after moving tabs to the QMenuBar
. This is in a context of a QtCore.Qt.FramelessWindowHint
QMainWindow.
I've tried setting the content margins of the every widgets / layouts to 0, but it doesn't seem to remove the extra space (in green on the screenshot).
Here's how the UI is structured:
- Green: QMainWindow
- Yellow: QTabWidget
- Red: QTabBar
- Blue: QMenuBar
Here's a minimal code snippet where I move tabs to the QMenuBar:
class MyWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__()
self.tab_widget = TabWidget()
def toggle_frameless(self):
layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self.menuBar().setLayout(layout)
self.menuBar().layout().addWidget(self.tab_widget.tab_bar)
self.menuBar().layout().addStretch()
I suspect that the QTabWidget keep the geometry of the tabs, but I can't find a way to remove this extra space. I'm attaching a screenshot to show the issue visually with colors on backgrounds: Any insights or solutions would be greatly appreciated!
Thanks in advance !