Python Forum

Full Version: Why widget is resized
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a QGridLayout that, when it is complete, has 3 columns. I don't understand something though. Column 0 is a fixed-width frame (has Qlabels in it, but doesn't matter re: this question), column 1 is a QTableView, and column 2 is a QLabel set to an image.

Here's what I don't understand: I have reimplemented sizeHint for the QTableView, and when coulmn 2 is not set (gridded), the tableview follows the size returned by its sizeHint. But, if coulmn 2 is set (gridded), the tableview shrinks to it's default size (returned by QTableView.size(), which never changes in my testing). Why does it behave like this? How can I get my tableview to follow its sizeHint in all conditions?
Little twist I'm discovering: the larger the image label grows, the more the tableview shrinks back to the default size.
Well, I worked around the issue, but I never did find out why the middle column shrinks. The tableview does not have a default true WidthForHeight policy (I just thought to look at the label, but don't think it will make a difference), so that's all I got.

But, what I did was set a fixed size policy for the tableview initially, and then set it back to it default (Expanding) after the image label loads. I had to use a QTimer, but no biggie. So, that's that for anyone interested.

Lightning struck my brain. I have solved the sizing issue in a non-hacky way. I reimplemented size() as well. So with sizeHint() and size() reimplemented, the tableview stays at the right size. I still don't know why a large widget size shrinks another widget to either it's size or size hint. If size() is reimplemented (and not sizeHint()), when the large image loads, the tableview shrinks to it's sizeHint(). If sizeHint() is reimplemented (and not size()), the tableview shrinks to its size(). There's probably another non-hackway to solve this by understanding layouts, but I can't figure it.
You can load the image in the QLabel in such a way that it doesn't change the size of the QLabel.
I don't want to do that though. I want the image to be a certain size--a portion of the app's fixed size. I did not know that though. You can scale PixMaps, so you can just use scaled(), which I'm familiar with. Thanks though.