Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. List View only displaying the first item

List View only displaying the first item

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 301 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.
  • M Offline
    M Offline
    MackS
    wrote on last edited by
    #1

    I have a list view trying to display a QStringList that I populate in C++. I've printed the count in both C++ and in the one QString that gets displayed via: text: listView.count. So I know that it receives the full list, but it only displays the first item.

    QML:

       ListView {
             id: myListView
             Layout.margins: 8
             spacing: 5
             model: myQStringListFromC++
             delegate: Text {
                 text: "- " + modelData
             }
       }
    

    C++:

    QStringList MyApp::getStringListToDisplay() const {
        QStringList ret;
        auto stringsToAdd= vectorOfStrings;
        for(auto aString: stringsToAdd) {
                ret.push_back(QString::fromStdString(aString));
        }
        return ret;
    }
    

    I've made sure that the QStringList Q_PROPERTY gets refreshed, but it still doesn't want to display the whole list.

    Thank you!

    GrecKoG 1 Reply Last reply
    0
    • M MackS

      I have a list view trying to display a QStringList that I populate in C++. I've printed the count in both C++ and in the one QString that gets displayed via: text: listView.count. So I know that it receives the full list, but it only displays the first item.

      QML:

         ListView {
               id: myListView
               Layout.margins: 8
               spacing: 5
               model: myQStringListFromC++
               delegate: Text {
                   text: "- " + modelData
               }
         }
      

      C++:

      QStringList MyApp::getStringListToDisplay() const {
          QStringList ret;
          auto stringsToAdd= vectorOfStrings;
          for(auto aString: stringsToAdd) {
                  ret.push_back(QString::fromStdString(aString));
          }
          return ret;
      }
      

      I've made sure that the QStringList Q_PROPERTY gets refreshed, but it still doesn't want to display the whole list.

      Thank you!

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @MackS Your ListView has a size of 0x0. It displays delegates in its available size, but since there is no space to do so it only displays one.

      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