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. How to use layout for custom QML item?
QtWS25 Last Chance

How to use layout for custom QML item?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 732 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
    ManhNT
    wrote on last edited by
    #1

    Hi, I describe my problem here: https://pastebin.com/fiu5dn1J
    Can anyone give me some suggestions?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      Hi @ManhNT

      According to the Qt doc

      http://doc.qt.io/qt-5/qml-qtquick-flow.html#details

      The Flow item automatically positions the child *Text* items side by side

      I think that, this why it worked for you with Text element

      The doc also says:

      If an item within a Flow is not visible, or if it has a width or height of 0, the item will not be laid out and it will not be visible within the Flow. Also, since a Flow automatically positions its children, a child item within a Flow should not set its x or y positions or anchor itself with any of the anchor properties.

      I think that you need to specify width and height for your custom items,

      Here is my tested sample (work after test)

      TestItem.qml

      Item {
          id: testItem
          property string text: value
          height: 100
          width: 100
      
          Text {
              text: testItem.text
              width: parent.width
              height: parent.height
          }
      }
      

      main.qml

      Flow {
              spacing: 10
      
              TestItem
              {
                  text: "one"
              }
              TestItem
              {
                  text: "two"
              }
              TestItem
              {
                  text: "three"
              }
          }
      

      Hope this can help you,,

      Best regards !

      1 Reply Last reply
      1
      • M Offline
        M Offline
        ManhNT
        wrote on last edited by
        #3

        Hi @mostefa, setting width and height for the item solved the problem.
        Thank you very much.

        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