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. bindings inside Repeater to outside properties don't work (?)

bindings inside Repeater to outside properties don't work (?)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
bindingrepeater
4 Posts 3 Posters 962 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.
  • J Offline
    J Offline
    jimav
    wrote on 11 Mar 2019, 02:54 last edited by jimav 3 Nov 2019, 03:00
    #1

    [https://doc.qt.io/qt-5/qml-qtqml-qt.html](link url) has a non-working example for using Qt.callLater() which purports to show a Column of strings and make them all display with the width of the widest string (the widths of the string do not change as intended).

    I tried to figure out why. It has nothing to do with Qt.callLater(), but a seemingly fundamental issue of how bindings work (did that example ever work in older releases?)

    Here is a cut-down example of the problem:

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    
    ApplicationWindow {
        visible:true
    
        Column {
            id: column
            property real widestChild: 50
            Repeater {
                id: repeater
                model: 4
                delegate: Rectangle {
                  width: column.widestChild  //*** DOES NOT WORK
                  height: 20
                  color: "lightblue" 
                  border.width: 1
                }
            }
        }
    }
    

    The binding

    width: column.widestChild
    

    seems to have no effect. Nothing is displayed at all, as if width were zero (in the non-working example cited above "widestChild" is computed and set on a onChildrenChanged signal, but in this cut-down example it is a constant).

    Why doesn't this work?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 11 Mar 2019, 04:47 last edited by
      #2

      You can try width: parent.widestChild. It should work.

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Shrinidhi Upadhyaya
        wrote on 11 Mar 2019, 05:09 last edited by
        #3

        Hi @jimav , i think Qt actually treats "column" as a keyword,so if you replace the id with something else for example:-

         Column {
           id: sampleColumn
           property real widestChild: 50
           [..]
           [..]
           delegate: Rectangle {
           width: sampleColumn.widestChild
           height: 20
            [..]
            [..]
          }
        }
        

        it works. And if you try to print it, it is "undefined"
        For Example:-

         Component.onCompleted: {
               console.log(column.widestChild)
         }
        

        And if you take the example given in the [https://doc.qt.io/qt-5/qml-qtqml-qt.html], actually that also does not work, if you try to print "column.widestChild" in that example it comes as "undefined", you can try it by pasting the above code inside the Text like i have done below:-

        [..]
        [..]
        Repeater {
                   id: repeater
                   model:columnTexts[currentTextModel%3]
                   delegate: Text {
                       color: "white"
                       text: modelData
                       width: column.widestChild
                       horizontalAlignment: Text.Center
        
                       //####Try this####
                       Component.onCompleted: {
                           console.log(column.widestChild)
                       }
        
                       Rectangle { anchors.fill: parent; z: -1; color: index%2 ? "red" : "darkgray" }
                   }
               }
        [..]
        [..]
        

        The only reason the why text or the rectangle is visible to you is because the Text is taking width with respect to the length of strings inside "property var columnTexts:[..]"

        0_1552280851366_ColumnIssueQtForum.PNG

        Shrinidhi Upadhyaya.
        Upvote the answer(s) that helped you to solve the issue.

        1 Reply Last reply
        1
        • J Offline
          J Offline
          jimav
          wrote on 11 Mar 2019, 19:05 last edited by jimav 3 Dec 2019, 00:29
          #4

          Ok, it looks like a bug introduced since Qt 5.8. I filed a bug report:
          https://bugreports.qt.io/browse/QTBUG-74332

          1 Reply Last reply
          0

          1/4

          11 Mar 2019, 02:54

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved