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. QML thumbnail list

QML thumbnail list

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.9k Views 1 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 Offline
    J Offline
    jimmy274
    wrote on last edited by
    #1

    Hi all,

    I have a problem making a thumbnail list/view in QML - I have no idea where to start with this. I've been searching a lot through Qt documentation and stackoverflow, but even though there are some "solutions", they are either not working for my system or not flexible enough. So, the end-effect should be an app similar to Android gallery - once Gallery is loaded, all the images are refreshed. User should also be able to delete images and so on.

    I should point out that there is quite some C++ code in the underlying Qt app, and QML frontend is only constructed via

    [code]
    QQmlApplicationEngine engine(QUrl("qrc:///camera_app.qml"));
    [/code]

    in main.cpp.

    I've created a GridView and statically assigned some images to it and it looks good. The static allocation looks like this:

    [code]
    ListModel {
    id: imageModel
    ListElement {
    name: "Image 01"
    imageUrl: "file:///home/DCIM/image_0000.jpeg"
    }
    ListElement {
    name: "Image 02"
    imageUrl: "file:///home/DCIM/image_0001.jpeg"
    }
    ListElement {
    name: "Image 03"
    imageUrl: "file:///home/DCIM/image_0002.jpeg"
    }
    ListElement {
    name: "Image 04"
    imageUrl: "file:///home/DCIM/image_0003.jpeg"
    }
    }
    [/code]

    However, I'm yet to find a way to dynamically add/remove pictures to/from imageModel. I have tried several ways including trying to do it from C++ with setContextProperty(), but they're not flexible enough, since this requires a pointer to the quickview, which is only available in my main.cpp, not in my underlying c++ code... Not to mention that it doesn't really work, since my ListModel is not in the main QML file. There is also a way to expose C++ model to the QML, but this exposes only model structure, not the list, so I can't really use it (or don't know how to).

    I would really appreciate some help here, as this is the only thing that's been blocking me. In contrast I thought that this would be an easy part... So basically any guidance/advice for some sort of gallery would do just fine. Thanks!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Did you look at ListModel insert(...) set(...) etc method. Based on some user action you should be able do something like
      imageModel.insert(....)

      Please note insert expects you insert JSON object. Please look at the above documentation in Assistant. Still if you need help, I can give you code.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jimmy274
        wrote on last edited by
        #3

        Hi and thanks for replying. Yesterday I've had some success with append() method - I've realized that it shouldn't be that hard if I use underlying C++ for handling file names only - QML's ListModel append() would work just fine if my underlying C++ class could provide it with proper file names and file count, which is really easy to implement - I'll give it a go and post back.

        What I do find funny is that my whole app blocks when I instantiate the fore-mentioned ListModel without ListElements. My current workaround is to put one ListElement to it and then clear() the list when it's loaded, although this is quite dumb - do you have any idea why ListModel doesn't work when there's no elements in it at startup?

        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