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

Signal dataChanged breaks QListView in grid layout

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.9.3
    • 5.4.1
    • Widgets: Itemviews
    • None
    • Linux 3.19.2
    • 937ded010b09250c6ab9a57917f2e430fb5875f5

    Description

      Hello, I have a problem with a QListView in IconMode using a grid layout.

      When displayed for the first time, everything works like a charm (http://hpics.li/afafe3d), but if the underlying model updates it's content (using signal dataChanged), the updated items don't respect the grid size policy (http://hpics.li/035dcbf). Using model reset, the layout keeps it's integrity (but it messes up the selection model).

      Is this a bug or am I doing something wrong ?

      QListView initialization:

        //...
        ui -> listView -> setMovement(QListView::Static);
        ui -> listView -> setResizeMode(QListView::Adjust);
        ui -> listView -> setViewMode(QListView::IconMode);
        ui -> listView -> setGridSize( QSize(150, 100));
        ui -> listView -> setWrapping(true);
        ui -> listView -> setWordWrap(true);
        ui -> listView -> setMinimumHeight(100);
        //...
      

      Use dataChanged in model, breaks the grid layout:

        //...
        int index = storageUnits.indexOf(unit);
      
        if(index >= 0) {
          QModelIndex idx = createIndex(index, 0);
          emit dataChanged(idx, idx);
        }
      }
      

      Use reset in model, layout OK but impact other features of the app:

        //...
        beginResetModel();
        endResetModel();
      

      Please find attached a small example illustrating this behaviour (based on QStringListModel for the sake of conciseness)

      Attachments

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

        Activity

          People

            chehrlic Christian Ehrlicher
            papylhomme Michaël Lhomme
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes