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. “Solved”How to display pictures (jpg, png) in thumbnail view using QML?
Qt 6.11 is out! See what's new in the release blog

“Solved”How to display pictures (jpg, png) in thumbnail view using QML?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 7.2k 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.
  • K Offline
    K Offline
    kathy
    wrote on last edited by
    #1

    I have list of pictures and want to use GridView (XmlListModel or ListModel) to display pictures (jpg, png) in thumbnail view in QML. But I have no clue.

    Could anyone help me?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Create a list model, a custom delegate, and a GridView.

      Your delegate component should simply be an Image or something similarly simple to start with that displays the source url at the desired size.

      Your list model should contain ListElement items that contain the source URL of your images.

      In your GridView set the "model" property to your ListModel and the "delegate" property to your delegate component.

      Something along these lines (not tested):

      @
      ListModel {
      id: imageModel
      ListElement {
      name: "Image 01"
      imageUrl: "http://myserver/path/to/image01"
      }
      ListElement {
      name: "Image 02"
      imageUrl: "http://myserver/path/to/image02"
      }
      ListElement {
      name: "Image 03"
      imageUrl: "http://myserver/path/to/image03"
      }
      ListElement {
      name: "Image 04"
      imageUrl: "http://myserver/path/to/image04"
      }
      }

      Component {
      id: imageDelegate
      Column {
      width: 200
      height: 200
      Image { source: imageUrl }
      Text { text: name }
      }
      }

      GridView {
      model: imageModel
      delegate: imageDelegate
      anchors.fill: parent
      }
      @

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chuck Gao
        wrote on last edited by
        #3

        As ZapB reply, you can also use scaleMode, when use Image element to scale the original image to fit the item(thumbnail) size.

        Chuck

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          Ah yes, sorry I forgot to mention the scaleMode property. Thanks for reminding.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          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