Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-101874

Adjusting Policy of QTableView to its content is not working

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • 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
    • Widgets: Itemviews
    • None
    • Windows

    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 :

      1. Clone this github repository : https://github.com/embeddedmz/QTableViewAdjustPolicyNotWorkingProperly
      2. Open the CMakeLists.txt with Qt Creator, build, run the program and note whether the QTableView fits its content.
      3. 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.
      4. Build Qt5 64-bit base binaries with vcpkg : .\vcpkg install qt5-base:x64-windows
      5. Download and install CMake : https://cmake.org/
      6. 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.
      7. Click on Configure
      8. Choose Visual Studio 16 2019 as a generator
      9. Ensure that the platform is x64
      10. Click on "specify a toolchain file for cross-compiling"
      11. Click "Next" and then specify the VCPKG toolchain file (e.g. D:/vcpkg/scripts/buildsystems/vcpkg.cmake)
      12. Click Finish and then wait for CMake to complete its configuration, it must succeed !
      13. Click on Generate
      14. Click on "Open Project" to open the Visual Studio 2019 solution. You can then close CMake.
      15. Build and run the Visual Studio solution.
      16. 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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            embeddedmz Amine Mzoughi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes