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. The height of the rectangle through the Loader = 0. How to Fix

The height of the rectangle through the Loader = 0. How to Fix

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 1.0k 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.
  • V Offline
    V Offline
    vebmaster
    wrote on last edited by
    #1

    height rectLoader = 0. Why? Tell me what is wrong?

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Flickable {
            id: flic
            anchors.fill: parent
            contentWidth: wrapper.width
            contentHeight: wrapper.height
            ScrollBar.vertical: ScrollBar { }
            ScrollBar.horizontal: ScrollBar { }
    
            Column {
                id: wrapper
                spacing: 20
    //                anchors.fill: parent
    //                height: 1200;
    
                Rectangle {
                    width: 300
                    height: 300
                    color: "blue"
                }
                Rectangle {
                    id: rectB
                    width: 300
                    height: 300
                    color: "black"
                    MouseArea {
                        anchors.fill: parent
                        onClicked: console.log(rectLoader.height)
                    }
                }
                Rectangle {
                    id: rectLoader
                    anchors.top: rectB.bottom
                    anchors.bottom: butB.top
                    height: pageLoader.height
                    Loader {
                        id: pageLoader
                        source: "Page1.qml"
                    }
                }
                Button {
                    id: butB
                    //height: pageItem.height
                    text: "Закрыть"
                }
            }
    
        }
    }
    

    Page1.qml

    import QtQuick 2.7
    
    Item {
        id: pageItem
        height: pageColumn.height
        Column {
            id: pageColumn
            spacing: 30
            Text {
                text: "111"
                font.pointSize: 20
            }
            Rectangle {
                width: 100
                height: 400
                color: "green"
            }
            Rectangle {
                width: 100
                height: 400
                color: "red"
            }
        }
    }
    
    raven-worxR 1 Reply Last reply
    0
    • V vebmaster

      height rectLoader = 0. Why? Tell me what is wrong?

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Flickable {
              id: flic
              anchors.fill: parent
              contentWidth: wrapper.width
              contentHeight: wrapper.height
              ScrollBar.vertical: ScrollBar { }
              ScrollBar.horizontal: ScrollBar { }
      
              Column {
                  id: wrapper
                  spacing: 20
      //                anchors.fill: parent
      //                height: 1200;
      
                  Rectangle {
                      width: 300
                      height: 300
                      color: "blue"
                  }
                  Rectangle {
                      id: rectB
                      width: 300
                      height: 300
                      color: "black"
                      MouseArea {
                          anchors.fill: parent
                          onClicked: console.log(rectLoader.height)
                      }
                  }
                  Rectangle {
                      id: rectLoader
                      anchors.top: rectB.bottom
                      anchors.bottom: butB.top
                      height: pageLoader.height
                      Loader {
                          id: pageLoader
                          source: "Page1.qml"
                      }
                  }
                  Button {
                      id: butB
                      //height: pageItem.height
                      text: "Закрыть"
                  }
              }
      
          }
      }
      

      Page1.qml

      import QtQuick 2.7
      
      Item {
          id: pageItem
          height: pageColumn.height
          Column {
              id: pageColumn
              spacing: 30
              Text {
                  text: "111"
                  font.pointSize: 20
              }
              Rectangle {
                  width: 100
                  height: 400
                  color: "green"
              }
              Rectangle {
                  width: 100
                  height: 400
                  color: "red"
              }
          }
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @vebmaster
      try the following:

      Item {
          id: pageItem
          height: pageColumn.implicitHeight
      
          ....
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      V 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @vebmaster
        try the following:

        Item {
            id: pageItem
            height: pageColumn.implicitHeight
        
            ....
        }
        
        V Offline
        V Offline
        vebmaster
        wrote on last edited by
        #3

        @raven-worx No, fail

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qnope
          wrote on last edited by
          #4

          I guess it is :

          height: pageLoader.height
          

          try

          height:pageLoader.item.height
          

          instead

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vebmaster
            wrote on last edited by
            #5

            Solution: Move the Loader of the Rectangle:

            import QtQuick 2.7
            import QtQuick.Controls 2.0
            import QtQuick.Layouts 1.0
            
            ApplicationWindow {
                visible: true
                width: 640
                height: 480
                title: qsTr("Hello World")
            
                Flickable {
                    id: flic
                    anchors.fill: parent
                    contentHeight: wrapper.height
                    ScrollBar.vertical: ScrollBar { }
                    ScrollBar.horizontal: ScrollBar { }
            
                    Column {
                        id: wrapper
                        spacing: 20
                        width: flic.width
            
                        Rectangle {
                            width: 300
                            height: 300
                            color: "blue"
                        }
                        Rectangle {
                            id: rectB
                            width: 300
                            height: 300
                            color: "black"
                            MouseArea {
                                anchors.fill: parent
                                onClicked: console.log(rectLoader.height)
                            }
                        }
                        Loader {
                            id: pageLoader
                            source: "Page1.qml"
                        }
                        Button {
                            id: butB
                            text: "Закрыть"
                        }
                    }
            
                }
            }
            
            

            Page1.qml

            import QtQuick 2.7
            
            Column {
                id: pageColumn
                spacing: 30
                Text {
                    text: "111"
                    font.pointSize: 20
                }
                Rectangle {
                    width: 100
                    height: 400
                    color: "green"
                }
                Rectangle {
                    width: 100
                    height: 400
                    color: "red"
                }
            }
            
            
            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