Tab resizing issues
-
Using PySide6 I have two tabs , one is called output and displays the current output. The second tab is called log and contains the history of all output. I want the information placed in the log to maintain the same size as it had in the output tab. The user should be able to scroll through the log. The log tab keeps growing in size. That unfortunately makes the output tab grow to the same size as the log tab even though the content of the output tab does not need that extra size. I understand that is the default. How do I override the default and make both the output tab and the log tab only as large as each needs to be?
-
@Ed-Schneider said in Tab resizing issues:
make both the output tab and the log tab only as large as each needs to be?
I could be mistaken :) but I think tabs have to be the same size as each other. And they grow to the size of the largest. That is my recollection.
[EDIT If that's wrong you could try setting a different fixed size on each tab widget and see how that behaves?]
You can control the content you put on them with layouts, so you don't occupy unwanted areas, with scrollbars or spacers.
-
@Ed-Schneider said in Tab resizing issues:
as long as the log tab could be scrollable without impacting the size of the output tab
So far as I know, if you put a scroll area (of a certain size) on one tab and content goes inside that, then it would not cause that tab or another tab to grow.
You may have to provide a minimal example of your code.
-
@JonB I would love to share my code but this issue is embedded in a 15,000+ line application. Believe me adding to a scrollable area does enlarge its size and more importantly the size of other tabs. I am hoping that proper setting of resizing policies (on the tables going onto the tab and/or on the scrollable area) might avoid this. So far I've not found the solution. So I must humbly disagree with your assertion. Something more is involved here.
-
If you want to keep the sizes of your "output" and "log" tabs separate, while still making the "log" tab scrollable without influencing the "output" tab's size, a good practice is to place the content of each tab within a scrollable area. Be sure to configure the resizing policies appropriately. Good luck
-
@JonB I found on StackOverflow someone bringing up the same issue. It was 8 years old so I needed to bring it up to PySide6. It does indeed show the same problem, one tab needing to be large forcing the smaller tab to grow, needlessly to the same size. There is an answer which looks like it might work but I could not see how to implement it. In the code I've commented out code corresponding to the answer.
#!/bin/python import sys from PySide6 import QtGui, QtCore, QtWidgets from PySide6.QtWidgets import (QApplication, QMainWindow, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget, QTabWidget, QLayout, QSizePolicy) class TabExample(QtWidgets.QWidget): def __init__(self): super(TabExample, self).__init__() self.initUI() def initUI(self): self.vbox_main = QtWidgets.QVBoxLayout() self.table_blank = QtWidgets.QTableWidget(10, 4) self.tabw = QtWidgets.QTabWidget() self.tab_A = QtWidgets.QWidget() self.vbox_A = QtWidgets.QVBoxLayout(self.tab_A) for i in range(40): lab = QtWidgets.QLabel('label %d' %i) self.vbox_A.addWidget(lab) self.tab_B = QtWidgets.QWidget() self.vbox_B = QtWidgets.QVBoxLayout(self.tab_B) for i in range(5): lab = QtWidgets.QLabel('labelB %d'%i) self.vbox_B.addWidget(lab) #COMMENT OUT NEXT LINE TO SEE DESIRED SIZE OF TAB B self.tabw.addTab(self.tab_A, 'Tab A') self.tabw.addTab(self.tab_B, 'Tab B') self.vbox_main.addWidget(self.table_blank, 1) self.vbox_main.addWidget(self.tabw) self.setLayout(self.vbox_main) self.setGeometry(0,0, 400, 600) #self.move(QtGui.QDesktopWidget().availableGeometry().center() - self.frameGeometry().center()) self.show() # def __init__(self): # super(TabExample, self).__init__() # self.initUI() # #self.tabWidget_2.currentChanged.connect(self.updateSizes) # #self.tab_B.parentWidget().connect(lab,800,600) # # self.tab_B.currentChanged.connect(self.updateSizes) # def updateSizes(self): # for i in range(self.tabWidget_2.count()): # #self.tabWidget_2.widget(i).setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) # self.tab_B.widget(i).setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) # # #current = self.tabWidget_2.currentWidget() # current = self.tab_B.currentWidget() # current.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) def main(): app = QtWidgets.QApplication(sys.argv) tabExample = TabExample() sys.exit(app.exec()) if __name__ == "__main__": main()