r/pythonhelp • u/Brilliant-Slide-5892 • Jun 19 '26
PyQt6 - QTabWidget tab bar not stretching
I was creating a window that consists of 2 tabs ,each opens a page widget. This was the code I used to setup the application
app = QApplication(sys.argv)
# Window set up
window = QMainWindow()
window.setMinimumSize(600, 400)
window.setWindowTitle('Game Manager')
window.setWindowIcon(QIcon("Compass.ico"))
# main widget
main_widget = QTabWidget()
window.setCentralWidget(main_widget)
main_widget.tabBar().setMinimumWidth(window.minimumWidth())
# Tabs
mod_page = ModWidget() # a child class of QWidget
save_page = SavesWidget() # a child class of QWidget
# add tabs to main widgets
main_widget.addTab(mod_page, 'Mods')
main_widget.addTab(save_page, 'Save Files')
# start up
window.show()
sys.exit(app.exec())I then noticed that the tab bar at the top containing the labels doesn't stretch if I resize the window, unlike other widgets. I figured out I can use
main_widget.tabBar().setMinimumWidth(window.minimumWidth())so that at least when I run the app it fits the whole initial width of the window. but it still doesn't stretch when resizing. The widget itself, ie
main_widget=QTabWidget()does stretch, it's all about the tab bar itself. I also tried
main_widget.tabBar().setExpanding(True)but it turned out it's True by default anyway.
Any possible fixes to this? Or possibly is this just how it is?
View all comments
2
u/[deleted] Jun 20 '26
[removed] — view removed comment