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

The view's spacing incorrect in certain situation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.4.0 Beta2
    • Widgets: Itemviews
    • None
    • Linux/X11

    Description

      An empty view which contains an QStandardModel and is setted a delegate to paint items.

      The view is setted wrapping to true. // this is necessary

      And the Item's width is little bigger than viewport's width minus double spacing(spacing is 40 and the item's width is width - 79)

      Then the spacing of the top item gets to 80(double spacing)

      I'm not sure if this is a BUG, can be reproduce in multi versions of Qt.

      I tested it in Qt 6.4.0

       

      this is the main code.

      //代码占位符
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent), ui(new Ui::MainWindow)
      {
          ui->setupUi(this); // there is only a QListView in the UI file.
          QStandardItemModel *model = new QStandardItemModel(this);
          model->appendRow(new QStandardItem("hello Qt"));
          model->appendRow(new QStandardItem("hello Dtk"));
          ui->listView->setModel(model);
          ui->listView->setSpacing(40);
          ui->listView->setFlow(QListView::LeftToRight);
          ui->listView->setItemDelegate(new Delegate(ui->listView));
          ui->listView->setResizeMode(QListView::Adjust);
          ui->listView->setWrapping(true);   // this is necessary and will not be reproduce if it's not setted.
      }
      

       ---

      this is the execution

      Red rectangle is the item, green line is the width of the Item, and black line is the spacing.

      if the item's width is less than viewport's width - 2 * spacing, or view->setWrapping(false) is setted, the top spacing is correct.

      Attachments

        1. Demo.zip
          3 kB
          St Xu
        2. image-2022-08-10-10-00-40-058.png
          36 kB
          St Xu
        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
            xust St Xu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes