Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal dataChanged breaks QListView in grid layout ?
QtWS25 Last Chance

Signal dataChanged breaks QListView in grid layout ?

Scheduled Pinned Locked Moved General and Desktop
qlistview
9 Posts 3 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    papylhomme
    wrote on last edited by
    #1

    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();
    
    P 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you create a minimal compilable example that shows this behavior ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Can you create a minimal compilable example that shows this behavior ?

        P Offline
        P Offline
        papylhomme
        wrote on last edited by
        #3

        @SGaist Thanks for the quick reply. I posted a small example here.

        On my box (running Linux and Qt5.4.1), clicking the button trigger the problem.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Looks like the word wrapping option gets killed somehow.

          You should check the bug report system to see if it's something known. If not please consider opening a new bug report providing your code example with the corresponding pro file

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P papylhomme

            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();
            
            P Offline
            P Offline
            papylhomme
            wrote on last edited by
            #5

            For future reference, as a workaround we can implement SizeHintRole from the model to fix the view behaviour:

            QVariant MyModel::data(const QModelIndex &index, int role) const {
              if(role == Qt::SizeHintRole)
                return QVariant(QSize(150, 100));
              //..
            }
            
            1 Reply Last reply
            0
            • N Offline
              N Offline
              Neer
              Banned
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Did you report the bug ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  papylhomme
                  wrote on last edited by
                  #8

                  Just reported it, here it is : https://bugreports.qt.io/browse/QTBUG-45427

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Thank you very much

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved