[Solved] How to make QTableWidget fill entire area of available space?
-
Hi,
In the Main Window of my application I have a QFrame (say frame1) with GridLayout. I have added one more QFrame (say frame2) in it along with horizontal & vertical spacers through .ui file.
I had created frame2 for a particular scenario, but I dont need it in current scenario.
So I am removing it from frame1 & deleting it.
Now I am creating a QTableWidget by code & adding it in position 0,0 of gridlayout of frame1.
The problem is that initially it is created with a fixed size. Now when I am adding rows & columns its size is not increasing & it is creating Scroll Bar's. Could it be because of the Spacer's? I want the table to adjust its size according to the no of rows & columns. I do not want it to create Scroll bar's & even if it its size increasing more than my window than I have a QScrollArea which is the parent of frame1. So it will create the Scroll bar's.
So how do I get the required behaviour?
Maybe it is confusing to get the question, please ask if you did not understand anything.
Thank You. -
You need to provide some code about how you are implementing, try to set the sizePolicy,
@yourTableWiget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);@
-
You'll probably have to resize your TableWidget yourself, calculating the necessary space each time an item is added or removed. (Be aware of the size policy in this case, perhaps you'll have to also change the minimum/maximum sizes each time)
By default, changing the contents of a tablewidget won't affect the outer size of the widget, no matter how the layout / spacers and size policies around it are set.
So this will be quite a complicated task... -
@Sam I will try that.
@Mr. Universe Thank You! Looks like I have some hard work ahead :)