Solved Qt Designer cannot set QTableWidget header column narrow
-
Using Qt Designer (4.8.1, Qt 5.12.2) on a
QTableWidget
I want to set all columns narrower than the default 50. I claim this does not work at run-time.From Designer:
horizontalHeaderDefaultSectionSize
: 33horizontalHeaderMinimumSectionSize
: 30
This shows up just as it should viewing the Designer
ui
file. So far so good.In the generated
ui_....h
file code generated shows:tableWidget_randDTable->horizontalHeader()->setDefaultSectionSize(33); tableWidget_randDTable->horizontalHeader()->setMinimumSectionSize(30);
Again good.
But at run-time columns are not narrow, I think they revert to the default of 50.
To "workaround" I go into my constructor code and add (after the
ui->setupUi(this);
):int temp = ui->tableWidget_randDTable->horizontalHeader()->defaultSectionSize(); ui->tableWidget_randDTable->horizontalHeader()->setDefaultSectionSize(33);
Calling
setDefaultSectionSize(33)
makes it work.temp
reports 50. Like it never got changed.What's going on?? I wonder whether in the Designer generated code, when it goes
setDefaultSectionSize(33)
it has not yet reducedminimumSectionSize
from the default to 50 to below the new default, and so setting the default does not work?? But I cannot affect the order of the lines generated from the .ui.Would someone be kind enough to verify? Any better workaround, because this is not good?
EDIT I just went into the
ui_....h
generated file. I manually swapped the lines totableWidget_randDTable->horizontalHeader()->setMinimumSectionSize(30); tableWidget_randDTable->horizontalHeader()->setDefaultSectionSize(33);
I managed to get it to recompile without regenerating from
.ui
. Sure enough, now it works!So.... provided you agree I now have a major problem, because the code as generated automatically is always to going to output in the order to stop narrowing default column width below 50 (before the line to reduce the minimum) is never to going to work, is it...?
-
Sorry, did not saw it. 5.12.2 is too old - you need 5.12.3: https://codereview.qt-project.org/c/qt/qttools/+/255813
-
Hi
Win 10. Qt 5.14.1 . visual stud 2017For me, its shown at runtime as it looks in Designer
Design
Runtime
-
I fixed this some time ago - what Qt version do you use? Or better - what Qt version does the uic executable use?
-
@mrjj, @Christian-Ehrlicher
Thanks for replying. Your posts crossed with my edit....I just reposted my finding above with the version numbers of Creator & Qt. Which I'm restricted to, because I use what ships with Ubuntu 19.04....
Using Qt Designer (4.8.1, Qt 5.12.2)
and so
uic
5.12.2.@Christian-Ehrlicher
If this has been fixed let me know (which version). I'll mark your post as solving, and think about how I can workaround. -
Sorry, did not saw it. 5.12.2 is too old - you need 5.12.3: https://codereview.qt-project.org/c/qt/qttools/+/255813
-
@Christian-Ehrlicher
Thanks Christian. Unfortunate it's 5.12.2 that ships with Ubuntu 19.04, just my luck, lol!I'll have to manage, and I guess I'll move up to 20.04 if/when it arrives....
-
If you are lucky 20.04 comes on April 23, 2020 :)
-
@mrjj If it comes out at present.... That's another month of wide columns .... ;-)
-
hehe in this virus infected world, i find wide columns to be of very little concern :)
But they are normally on time so you could be lucky :) -
@mrjj You're right --- columns must now stand a minimum of 50 pixels apart for safety, lol ;-)
-
@JonB
Haha. Perfect answer if any user asks :)