Automatically stretch QTableWidget to fit resized window
-
@skebanga
It's not my day today. Indeed you do need to create it, I rely on the form editor too much and am losing touch with coded layouts/windows it seems. -
Thanks for the suggestion.
In terms of the layouts and widgets I used in my example, it was a stripped down version of something I have already in my app framework - stripped down to try make a MCVE.
What I actually have is something like a building block which I use to create custom "settings dialogs" for various different applications.
I have a central window with a
QFormLayout
at the top and aQHBoxLayout
at the bottom with save and cancelQPushButtons
.The
QFrames
haveQFrame::Panel
frame style to delineate them.The
QFormLayout
at the top is empty, and the various users add rows to it as they see fit.It sort of looks like this with nothing on it:
When the user wants to add a new row, they call the following function which gives them back a
QFormLayout
to which they can add whatever widgets they want:QFormLayout* SettingsDialog::addFormGroup(const QString& title) { QFrame* frame = new QFrame; frame->setFrameStyle(QFrame::Panel); _form_layout.addRow(frame); QFormLayout* form_group_layout = new QFormLayout; frame->setLayout(form_group_layout); if (!title.isEmpty()) form_group_layout->addRow(new QLabel(title)); return form_group_layout; }
Here is an example of it being used with 2 form group rows in the
QFormLayout
Here is me playing with getting the
QTableWidget
into my settings dialog:Here is the same
QTableWidget
settings dialog when resized, which I am struggling with:Sorry if this is getting a bit verbose. Hopefully I've managed to explain what I'm doing and why I have the weird combination of
QFrame
andQFormLayout
etc?Thanks for the assistance!
-
@skebanga
Why not just create a simple VBox layout to insert into your central widget layout and add the frames there? Seems the most simple solution to me. -
@skebanga
Not sure but please try this. I was facing similar issue , this solved it.
SearchTable->horizontalHeader()->setStretchLastSection(true); -
Thank you @SGaist and @kshegunov
Between your examples and suggestions I have managed to achieve what I want.
-
SearchTable->horizontalHeader()->setStretchLastSection(true);
I don't believe this is what I'm looking for here, as this is to stretch the last section of the table as the table is resized, whereas I want to stretch the table itself.
-
@skebanga
Good job! :) -
@skebanga
Hello. If you can please tell how did you achieve that . I have similar issuesThanks !!!
-
In PyQt5 How can this be done?
Automatically stretch PyQt5 Widgets to fit resized window?
please help me -
-
So basically, it's not possible. Got it.
-
Hi,
@nlcodes said in Automatically stretch QTableWidget to fit resized window:So basically, it's not possible. Got it.
You misunderstood what @JonB wrote. What he wrote is that you have to translate the C++ code you see above in its Python counterpart. That's all.