Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.0, 5.15.1, 5.15.6, 5.15.2, 5.15.3, 5.15.4, 5.15.5, 5.15.7, 6.2.3
-
None
Description
In short, on different Windows versions (8.1 and 10), using CMake and two different build procedures, QTableView's SizeAdjustPolicy::AdjustToContents adjust policy is not working.
Please look at this thread I have already opened in Qt Forums https://forum.qt.io/topic/135057/adjusting-qtableview-height-to-its-content-not-working-with-the-qt-installed-with-vcpkg-on-windows-10-vs-2019 Inside it, look at the link pointing to a StackOverflow question and at the link pointing to an issue I have opened on "vcpkg" github page.
I have posted 4 screenshots to illustrate this issue.
On the Qt thread, you will find the link to the github repo of the demo program I coded to make the screenshots.
Here's how reproduce this bug :
- Clone this github repository : https://github.com/embeddedmz/QTableViewAdjustPolicyNotWorkingProperly
- Open the CMakeLists.txt with Qt Creator, build, run the program and note whether the QTableView fits its content.
- Clone vcpkg : https://github.com/microsoft/vcpkg and follow the README.md's "Quick Start : Windows" section to set it up on a Windows OS.
- Build Qt5 64-bit base binaries with vcpkg : .\vcpkg install qt5-base:x64-windows
- Download and install CMake : https://cmake.org/
- Use CMake to generate a Visual Studio Solution : launch CMake, in "Where is the source code:" indicate the QTableViewAdjustPolicyNotWorkingProperly repo path and in "Where to build binaries:" indicate a path where the Visual Studio solution will be generated.
- Click on Configure
- Choose Visual Studio 16 2019 as a generator
- Ensure that the platform is x64
- Click on "specify a toolchain file for cross-compiling"
- Click "Next" and then specify the VCPKG toolchain file (e.g. D:/vcpkg/scripts/buildsystems/vcpkg.cmake)
- Click Finish and then wait for CMake to complete its configuration, it must succeed !
- Click on Generate
- Click on "Open Project" to open the Visual Studio 2019 solution. You can then close CMake.
- Build and run the Visual Studio solution.
- Note whether the QTableView fits its content.
UPDATE : On Qt 5.12.11 (MSVC 2017), there's no bug when the demo program is built using Qt Creator. There's clearly a code regression that happened between 5.12.11 (MSVC2017) and 5.15.2 (MSVC2019).
QSize QAbstractScrollArea::sizeHint() const
{
Q_D(const QAbstractScrollArea);
if (d->sizeAdjustPolicy == QAbstractScrollArea::AdjustIgnored)
return QSize(256, 192);
if (!d->sizeHint.isValid() || d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents)
{ const int f = 2 * d->frameWidth; const QSize frame( f, f ); const bool vbarHidden = d->vbar->isHidden() || d->vbarpolicy == Qt::ScrollBarAlwaysOff; const bool hbarHidden = d->hbar->isHidden() || d->hbarpolicy == Qt::ScrollBarAlwaysOff; const QSize scrollbars(vbarHidden ? 0 : d->vbar->sizeHint().width(), hbarHidden ? 0 : d->hbar->sizeHint().height()); d->sizeHint = frame + scrollbars + viewportSizeHint(); } return d->sizeHint;
}
The version used in Qt 5.12.11 :
QSize QAbstractScrollArea::sizeHint() const
{
Q_D(const QAbstractScrollArea);
if (d->sizeAdjustPolicy == QAbstractScrollArea::AdjustIgnored)
return QSize(256, 192);
if (!d->sizeHint.isValid() || d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents)
{ const int f = 2 * d->frameWidth; const QSize frame( f, f ); const QSize scrollbars(d->vbarpolicy == Qt::ScrollBarAlwaysOn ? d->vbar->sizeHint().width() : 0, d->hbarpolicy == Qt::ScrollBarAlwaysOn ? d->hbar->sizeHint().height() : 0); d->sizeHint = frame + scrollbars + viewportSizeHint(); } return d->sizeHint;
}
in any case, this method must be rewritten and it may not be obvious to handle the "ScrollBarAsNeeded" case at first glance