Adjust QTableView Height to its content (few lines)
-
wrote on 8 Sept 2021, 10:24 last edited by
The number of rows are fixed !
-
wrote on 8 Sept 2021, 10:30 last edited by
You don't have to do it manually, just call
view->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
-
You don't have to do it manually, just call
view->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
wrote on 8 Sept 2021, 10:35 last edited by deleted343 9 Aug 2021, 10:41@VRonin I removed verticalResizeTableViewToContents() and used your code in the constructor and I still have the same resultats as verticalResizeTableViewToContents(). I have also set it in the UI file.
When I shrink the windows and make scroll bars appears on the table view, there is no extra white space but I think it's normal.
and if I don't do nothing at all the extra white space is larger !
-
wrote on 8 Sept 2021, 10:46 last edited by deleted343 9 Aug 2021, 10:54
and even in I set the number of rows in the model to 0, I still have a white space after the columns header :
int MeasuresModel::rowCount(const QModelIndex& parent /*= QModelIndex()*/) const { Q_UNUSED(parent) return 0; }
I noticed something very weired when I use this size policy :
m_Internals->Ui.Measures->setSizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Minimum);
The width of the windows keeps growing indefinitely !!! Anyway, I even tried changing the size policy of the parents.
-
wrote on 8 Sept 2021, 19:24 last edited by
Do you have a spacer at the bottom to fill the empty space? You need something to fill the empty space or you'll get weird results from the layout widget.
-
wrote on 10 Sept 2021, 07:09 last edited by
I have already a spacer, I also tried by adding another one but the table is still taking space.
Btw, when I deleted my Qt account because I was unable to download the open source installer with it, it deleted also my forum account :(
-
wrote on 10 Sept 2021, 12:21 last edited by embeddedmz_2 9 Oct 2021, 16:55
Update : I made a small example to reproduce this issue with QTableView : https://github.com/embeddedmz/QTableViewAdjustPolicyNotWorkingProperly
Using the latest Qt version (from Qt official installer), there's no issue. However, using the Qt library provided by vcpkg (outdated for sure) the issue is there.
With the latest Qt provided by the Qt Company :
I will make a git pull on my vcpkg repo, update Qt and check if this issue disappears with the last version of Qt provided by vcpkg ! With vcpkg last Qt5 version the issue is still present and Qt6 libraries have an issue that I reported here : https://github.com/microsoft/vcpkg/issues/20101
-
wrote on 13 Sept 2021, 07:31 last edited by
I have tested the code I published on github on Windows 8.1 + vcpkg and I don't have the issue that I got with Win10 + vcpkg.
On StackOverflow.com, someone gave me this workaround :
you can also fix your problem with one trick, this problem happens for you because your data is lower than the table size. I clone your project and change sizepolicy
-
I have tested the code I published on github on Windows 8.1 + vcpkg and I don't have the issue that I got with Win10 + vcpkg.
On StackOverflow.com, someone gave me this workaround :
you can also fix your problem with one trick, this problem happens for you because your data is lower than the table size. I clone your project and change sizepolicy
Hi
So did the work around fix it ? -
Hi
So did the work around fix it ?wrote on 24 Aug 2022, 13:37 last edited by@mrjj the issue is with QSize QAbstractScrollArea::sizeHint() which is not well implemented (buggy), I have already reported this issue in the report QTBUG-101874.
After reading the code of sizeHint, I found that by setting the verticalScrollBarPolicy to ScrollBarAlwaysOff, the extra space will not be added at the end of the table.
Under Qt 5.12.11, there's no issue since the sizeHint's implementation is different from that of more recent versions of Qt.
Hope that helps other people.