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. QListView is asking the model for data but not displaying it.
Qt 6.11 is out! See what's new in the release blog

QListView is asking the model for data but not displaying it.

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 2.4k Views 2 Watching
  • 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.
  • J.HilkJ J.Hilk

    hi @Stokestack
    did you maybe forget to give your delegate a hight and width?

    StokestackS Offline
    StokestackS Offline
    Stokestack
    wrote on last edited by
    #3

    @J.Hilk Thanks for your reply.

    Well... maybe. Height and width of what? The control itself is laid out on a form using the design tool. Based on your question, I'm looking for inquiries that request width & height but haven't found any yet...

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

      Hi,

      Can you show your model implementation ?

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

      StokestackS 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Can you show your model implementation ?

        StokestackS Offline
        StokestackS Offline
        Stokestack
        wrote on last edited by Stokestack
        #5

        @SGaist Sure. Well, any part that's relevant to the listview. It's a pretty big class; because this listview is only to provide a display of detected Bluetooth devices, I've made my Bluetooth-finder class the model as well.

        // Methods to support QAbstractListModel
        
        int DeviceFinder::rowCount(const QModelIndex& parent) const
        {
        	return static_cast<int>(m_foundDevices.size());
        }
        
        
        QVariant DeviceFinder::data(const QModelIndex& index, int role) const
        {
        	shared_ptr<BTDevice> pThisDevice = m_foundDevices.at(static_cast<unsigned long int>(index.row()));
        	qDebug() << "DeviceFinder::data returning " << pThisDevice->getUUID() << " for row " << index.row();
        	return pThisDevice->getUUID();
        }
        

        The debug output shows I'm getting legit strings.

        1 Reply Last reply
        0
        • StokestackS Stokestack

          @J.Hilk Thanks for your reply.

          Well... maybe. Height and width of what? The control itself is laid out on a form using the design tool. Based on your question, I'm looking for inquiries that request width & height but haven't found any yet...

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #6

          @Stokestack
          I'm sorry, I don't know why, but thought this to be in the QML sub forum.

          My previous post relates to the QML ListView object. My bad.

          But, I think the issue might be similar.
          To display data in a ListView you need 3 things,

          • A model
          • A ListView
          • A Delegate

          In your op you mention point 1 and 2, what about the delegate, the object that is drawn inside your ListView and changes depending on the data in the model?
          Did you touch that or is it the "default" one?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          StokestackS 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Stokestack
            I'm sorry, I don't know why, but thought this to be in the QML sub forum.

            My previous post relates to the QML ListView object. My bad.

            But, I think the issue might be similar.
            To display data in a ListView you need 3 things,

            • A model
            • A ListView
            • A Delegate

            In your op you mention point 1 and 2, what about the delegate, the object that is drawn inside your ListView and changes depending on the data in the model?
            Did you touch that or is it the "default" one?

            StokestackS Offline
            StokestackS Offline
            Stokestack
            wrote on last edited by Stokestack
            #7

            @J.Hilk Thanks. It must be the default one, because I haven't seen any mention of a delegate in the docs.

            Interestingly, if I double-click in the top of the list area where items should be, the data model will be queried for the appropriate row...

            J.HilkJ 1 Reply Last reply
            0
            • StokestackS Stokestack

              @J.Hilk Thanks. It must be the default one, because I haven't seen any mention of a delegate in the docs.

              Interestingly, if I double-click in the top of the list area where items should be, the data model will be queried for the appropriate row...

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #8

              @Stokestack

              take a look here for more information
              https://doc.qt.io/qt-5/modelview.html#3-4-delegates

              and
              https://doc.qt.io/qt-5/qabstractitemdelegate.html


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              StokestackS 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #9

                And you really must respect the given role to data() and not simply return getUUID() for all roles...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • J.HilkJ J.Hilk

                  @Stokestack

                  take a look here for more information
                  https://doc.qt.io/qt-5/modelview.html#3-4-delegates

                  and
                  https://doc.qt.io/qt-5/qabstractitemdelegate.html

                  StokestackS Offline
                  StokestackS Offline
                  Stokestack
                  wrote on last edited by Stokestack
                  #10

                  @J.Hilk Thanks. I don't think it's a delegate problem. I've done demos from an instructional book as well, and no delegates were used for this kind of listview.

                  The clicking behavior is pretty telling; the items are in the list and they occupy space. They're just invisible.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @Stokestack said in QListView is asking the model for data but not displaying it.:

                    They're just invisible.

                    Did you read my post?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    StokestackS 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @Stokestack said in QListView is asking the model for data but not displaying it.:

                      They're just invisible.

                      Did you read my post?

                      StokestackS Offline
                      StokestackS Offline
                      Stokestack
                      wrote on last edited by Stokestack
                      #12

                      @Christian-Ehrlicher Yes, and I was just about to go and see if the listview was requesting decoration info or something and getting messed up by the strings...

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        There is nothing to see - a view takes all it's information from the model. You simply return a value for every role instead just Qt::DisplayRole and wonder why it's displaying mess.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        StokestackS 1 Reply Last reply
                        1
                        • Christian EhrlicherC Christian Ehrlicher

                          There is nothing to see - a view takes all it's information from the model. You simply return a value for every role instead just Qt::DisplayRole and wonder why it's displaying mess.

                          StokestackS Offline
                          StokestackS Offline
                          Stokestack
                          wrote on last edited by Stokestack
                          #14

                          @Christian-Ehrlicher And sure enough that was it. Thanks Christian! I thought that, by default, it was just going to ask for strings for each "role" of each element, with the roles basically being equivalent to columns. I didn't really care if it showed the same string for every role, but if it got a string it didn't understand for the Decoration role... I see where that might disrupt the whole display.

                          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