Python Forum
[PyQt] Why widget is resized
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Why widget is resized
#1
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?
Reply
#2
Little twist I'm discovering: the larger the image label grows, the more the tableview shrinks back to the default size.
Reply
#3
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.

EDIT:
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.
Reply
#4
You can load the image in the QLabel in such a way that it doesn't change the size of the QLabel.
Reply
#5
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020