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 a GridLayout in combination with exposing data property

How to use a GridLayout in combination with exposing data property

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 1.2k 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.
  • P Offline
    P Offline
    Phataas
    wrote on last edited by
    #1

    I am trying to wrap GridLayout inside an Item and exposing the GridLayout's data property as the default property of the item. But this results in two problems.

    1. I get a crash when exiting the application.

      • This may in fact be a bug in Qt itself and it might also already been fixed, if not I will report it after fixing 2. I am only able to test on Windows 7 using Qt 5.7.0 MSVC2015 32.bit at the moment.
    2. How to use the attached Layout property? Take look in the following example, which results in the error: "Non-existent attached object" on line "Layout.alignment: Qt.AlignBottom | Qt.AlignRight".

    //MyCustomLayout.qml
    import QtQuick 2.7
    import QtQuick.Layouts 1.3
    
    Item {
        default property alias data: layout.data
    
        //Some other QML components not to be within GridView here.
    
        GridLayout {
            id: layout
            anchors.fill: parent
        }
    
        //Some other QML components not to be within GridView here.
    
    }
    
    //main.qml
    import QtQuick.Controls 2.0
    
    ApplicationWindow {
        id: root
        visible: true
        height: 1024
        width: 768
    
        MyCustomLayout {
            anchors.fill: parent
    
            Button {
                Layout.alignment: Qt.AlignBottom | Qt.AlignRight
            }
        }
    }
    
    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      You item stucture is now:

      ApplicationWindow {
          Item{
              GridLayout {}
              Button{} }}
      

      not

      ApplicationWindow {
          Item{
              GridLayout {
                  Button{} }}}
      

      That causes number 2. The button isn't inside the layout.

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

        in addition to previous post, if you want to achieve the way your code exist, here is the sample.

        MyGrid.qml
        import QtQuick 2.7
        import QtQuick.Layouts 1.3

        Item {
        property alias lyout: lay
        GridLayout {
        id: lay
        anchors.fill: parent
        }
        function addObject(val){
        val.parent = lay
        }
        }

        =========
        MyApp.qml

        import QtQuick 2.5
        import QtQuick.Controls 2.0
        import QtQuick.Layouts 1.3

        ApplicationWindow {
        id: root
        visible: true
        height: 1024
        width: 768

        MyGrid {
            anchors.fill: parent
            id : myGrid
            Button {
                id : b1
                text : "Ali"
                Layout.alignment: Qt.AlignBottom | Qt.AlignRight
                parent : myGrid.lyout
            }
            Button {
                id : b2
                text : "Pradeep"
                Layout.alignment: Qt.AlignBottom | Qt.AlignRight
                parent : myGrid.lyout
            }
            Component.onCompleted:{
        

        // myGrid.addObject(b1)
        // myGrid.addObject(b2)
        // b1.parent = myGrid.lyout
        // b2.parent = myGrid.lyout
        }
        }
        }

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

        1 Reply Last reply
        4
        • E Eeli K

          You item stucture is now:

          ApplicationWindow {
              Item{
                  GridLayout {}
                  Button{} }}
          

          not

          ApplicationWindow {
              Item{
                  GridLayout {
                      Button{} }}}
          

          That causes number 2. The button isn't inside the layout.

          P Offline
          P Offline
          Phataas
          wrote on last edited by
          #4

          @Eeli-K Are you sure about that item structure? When aliasing the default property is should be added with the aliased origin as its parent no?

          E 1 Reply Last reply
          0
          • P Phataas

            @Eeli-K Are you sure about that item structure? When aliasing the default property is should be added with the aliased origin as its parent no?

            E Offline
            E Offline
            Eeli K
            wrote on last edited by
            #5

            @Phataas I see. Well, I don't know about that, but you can see the actual structure if you debug the qml code with QtCreator.

            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