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 ]Cant access alias from Item

[SOLVED ]Cant access alias from Item

Scheduled Pinned Locked Moved QML and Qt Quick
qt quickitemalias
14 Posts 3 Posters 11.9k 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.
  • G Offline
    G Offline
    guidupas
    wrote on 8 Jun 2015, 15:03 last edited by guidupas 6 Nov 2015, 15:02
    #1

    Hello!

    I am trying to access an alias from an Item and it is not working. Can anyone help me?

    In main.qml, when I try DelegateLancamentos.removeMouseArea: it returns this message:
    qrc:/DelegateLancamentos.qml:10 Invalid alias reference. Unable to find id "removeMouseArea"

    Code below:

    MainForm.ui.qml

    Rectangle {
        id: mainContainer
    
        property alias lancamentosListView: lancamentosListView
    
        width: 360
        height: 640
    
        ListView {
            id: lancamentosListView
    
            anchors.fill: parent
    
            clip: true
    
            spacing: 10
        }
    }
    

    ModeloLancamentos.qml

    ListModel {
        ListElement {
            valor: "25.000,00"
            tipo: "Investimento"
        }
    }
    

    DelegateLancamentos.qml

    Item {
        id: delegateItem
    
        property Component delegateComponent: delegateComponent
        property alias removeMouseArea: removeMouseArea
    
        Component {
            id: delegateComponent
    
            Row {
                Column {
                    width: 360 * 0.96 / 8 * 6
                    //width: Screen.width * 0.96 / 8 * 6
    
                    Text {
                        text: "<strong>" + "Valor: " + valor + "</strong>"
                        font.pixelSize: 16
                    }
                    Text {
                        text: "Tipo: " + tipo
                        font.pixelSize: 16
                    }
                }
    
                Column {
                    width: 360 * 0.96 / 8
                    //width: Screen.width * 0.96 / 8
    
                    Image {
                        id: removeImage
                        source: "Imagens/remove.png"
    
                        width: 35
    
                        fillMode: Image.PreserveAspectFit
    
                        MouseArea {
                            id: removeMouseArea
    
                            anchors.fill: parent
                        }
                    }
                }
            }
        }
    }
    

    main.qml

    Window {
        visible: true
    
        width: 360
        height: 640
    
        maximumHeight: 640
        minimumHeight: 640
    
        maximumWidth: 360
        minimumWidth: 360
    
        title: "InvestmentC-Mobile"
    
        MainForm {
            anchors.fill: parent
    
            mainContainer.width: parent.width
            mainContainer.height: parent.height
    
            lancamentosListView.model: modeloLancamentos
            lancamentosListView.delegate: delegateLancamentos.delegateComponent
    
            DelegateLancamentos.removeMouseArea:
            {
                modeloLancamentos.remove(index);
            }
        }
        
        ModeloLancamentos{
            id: modeloLancamentos
        }
    
        DelegateLancamentos {
            id: delegateLancamentos
        }
    }
    

    Att.
    Guilherme Cortada Dupas

    P T 2 Replies Last reply 8 Jun 2015, 16:54
    0
    • G guidupas
      8 Jun 2015, 15:03

      Hello!

      I am trying to access an alias from an Item and it is not working. Can anyone help me?

      In main.qml, when I try DelegateLancamentos.removeMouseArea: it returns this message:
      qrc:/DelegateLancamentos.qml:10 Invalid alias reference. Unable to find id "removeMouseArea"

      Code below:

      MainForm.ui.qml

      Rectangle {
          id: mainContainer
      
          property alias lancamentosListView: lancamentosListView
      
          width: 360
          height: 640
      
          ListView {
              id: lancamentosListView
      
              anchors.fill: parent
      
              clip: true
      
              spacing: 10
          }
      }
      

      ModeloLancamentos.qml

      ListModel {
          ListElement {
              valor: "25.000,00"
              tipo: "Investimento"
          }
      }
      

      DelegateLancamentos.qml

      Item {
          id: delegateItem
      
          property Component delegateComponent: delegateComponent
          property alias removeMouseArea: removeMouseArea
      
          Component {
              id: delegateComponent
      
              Row {
                  Column {
                      width: 360 * 0.96 / 8 * 6
                      //width: Screen.width * 0.96 / 8 * 6
      
                      Text {
                          text: "<strong>" + "Valor: " + valor + "</strong>"
                          font.pixelSize: 16
                      }
                      Text {
                          text: "Tipo: " + tipo
                          font.pixelSize: 16
                      }
                  }
      
                  Column {
                      width: 360 * 0.96 / 8
                      //width: Screen.width * 0.96 / 8
      
                      Image {
                          id: removeImage
                          source: "Imagens/remove.png"
      
                          width: 35
      
                          fillMode: Image.PreserveAspectFit
      
                          MouseArea {
                              id: removeMouseArea
      
                              anchors.fill: parent
                          }
                      }
                  }
              }
          }
      }
      

      main.qml

      Window {
          visible: true
      
          width: 360
          height: 640
      
          maximumHeight: 640
          minimumHeight: 640
      
          maximumWidth: 360
          minimumWidth: 360
      
          title: "InvestmentC-Mobile"
      
          MainForm {
              anchors.fill: parent
      
              mainContainer.width: parent.width
              mainContainer.height: parent.height
      
              lancamentosListView.model: modeloLancamentos
              lancamentosListView.delegate: delegateLancamentos.delegateComponent
      
              DelegateLancamentos.removeMouseArea:
              {
                  modeloLancamentos.remove(index);
              }
          }
          
          ModeloLancamentos{
              id: modeloLancamentos
          }
      
          DelegateLancamentos {
              id: delegateLancamentos
          }
      }
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 8 Jun 2015, 16:54 last edited by
      #2

      Hi @guidupas,
      alias's works with property and not with the Component itself.

      157

      1 Reply Last reply
      0
      • G guidupas
        8 Jun 2015, 15:03

        Hello!

        I am trying to access an alias from an Item and it is not working. Can anyone help me?

        In main.qml, when I try DelegateLancamentos.removeMouseArea: it returns this message:
        qrc:/DelegateLancamentos.qml:10 Invalid alias reference. Unable to find id "removeMouseArea"

        Code below:

        MainForm.ui.qml

        Rectangle {
            id: mainContainer
        
            property alias lancamentosListView: lancamentosListView
        
            width: 360
            height: 640
        
            ListView {
                id: lancamentosListView
        
                anchors.fill: parent
        
                clip: true
        
                spacing: 10
            }
        }
        

        ModeloLancamentos.qml

        ListModel {
            ListElement {
                valor: "25.000,00"
                tipo: "Investimento"
            }
        }
        

        DelegateLancamentos.qml

        Item {
            id: delegateItem
        
            property Component delegateComponent: delegateComponent
            property alias removeMouseArea: removeMouseArea
        
            Component {
                id: delegateComponent
        
                Row {
                    Column {
                        width: 360 * 0.96 / 8 * 6
                        //width: Screen.width * 0.96 / 8 * 6
        
                        Text {
                            text: "<strong>" + "Valor: " + valor + "</strong>"
                            font.pixelSize: 16
                        }
                        Text {
                            text: "Tipo: " + tipo
                            font.pixelSize: 16
                        }
                    }
        
                    Column {
                        width: 360 * 0.96 / 8
                        //width: Screen.width * 0.96 / 8
        
                        Image {
                            id: removeImage
                            source: "Imagens/remove.png"
        
                            width: 35
        
                            fillMode: Image.PreserveAspectFit
        
                            MouseArea {
                                id: removeMouseArea
        
                                anchors.fill: parent
                            }
                        }
                    }
                }
            }
        }
        

        main.qml

        Window {
            visible: true
        
            width: 360
            height: 640
        
            maximumHeight: 640
            minimumHeight: 640
        
            maximumWidth: 360
            minimumWidth: 360
        
            title: "InvestmentC-Mobile"
        
            MainForm {
                anchors.fill: parent
        
                mainContainer.width: parent.width
                mainContainer.height: parent.height
        
                lancamentosListView.model: modeloLancamentos
                lancamentosListView.delegate: delegateLancamentos.delegateComponent
        
                DelegateLancamentos.removeMouseArea:
                {
                    modeloLancamentos.remove(index);
                }
            }
            
            ModeloLancamentos{
                id: modeloLancamentos
            }
        
            DelegateLancamentos {
                id: delegateLancamentos
            }
        }
        
        T Offline
        T Offline
        t3685
        wrote on 8 Jun 2015, 17:10 last edited by
        #3

        @guidupas

        Try renaming your alias to something else:

        property alias myRemoveMouseArea: removeMouseArea

        1 Reply Last reply
        0
        • G Offline
          G Offline
          guidupas
          wrote on 8 Jun 2015, 17:27 last edited by
          #4

          @t3685

          It did not work.

          @p3c0

          Could you help me to solve it?

          Att.
          Guilherme Cortada Dupas

          T 1 Reply Last reply 8 Jun 2015, 17:35
          0
          • G guidupas
            8 Jun 2015, 17:27

            @t3685

            It did not work.

            @p3c0

            Could you help me to solve it?

            T Offline
            T Offline
            t3685
            wrote on 8 Jun 2015, 17:35 last edited by
            #5

            @guidupas

            Did read your code properly. You can't have alias to properties/elements of a Component.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              guidupas
              wrote on 8 Jun 2015, 17:58 last edited by
              #6

              @t3685
              First of all, thank you for the replies.

              Yes, I figured that out. Bur how could I make it work. There is someway to do something that could solve this?

              Thank you very much.

              Att.
              Guilherme Cortada Dupas

              T 1 Reply Last reply 8 Jun 2015, 19:27
              0
              • G guidupas
                8 Jun 2015, 17:58

                @t3685
                First of all, thank you for the replies.

                Yes, I figured that out. Bur how could I make it work. There is someway to do something that could solve this?

                Thank you very much.

                T Offline
                T Offline
                t3685
                wrote on 8 Jun 2015, 19:27 last edited by t3685 6 Aug 2015, 19:57
                #7

                @guidupas

                Hi,

                You need to work top down: create the necessary properties in delegateItem your removeMouseArea can access or have it call function or signals of delegateItem as needed. Why are you putting it in a Componentin the first place?

                G 1 Reply Last reply 8 Jun 2015, 21:25
                0
                • T t3685
                  8 Jun 2015, 19:27

                  @guidupas

                  Hi,

                  You need to work top down: create the necessary properties in delegateItem your removeMouseArea can access or have it call function or signals of delegateItem as needed. Why are you putting it in a Componentin the first place?

                  G Offline
                  G Offline
                  guidupas
                  wrote on 8 Jun 2015, 21:25 last edited by
                  #8

                  @t3685

                  Hey.

                  Because it is to delegate a model. When I put it inside an Item it behaves differently then a Component.

                  Att.
                  Guilherme Cortada Dupas

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    guidupas
                    wrote on 9 Jun 2015, 12:40 last edited by
                    #9

                    @t3685 @p3c0

                    What I really need is that:

                    In MainForm.ui.qml I have two rectangle. I need when i click the mouse area from a delegate component set rec1.visible = false and rec2.visible = true (files below)

                    How can I do that?

                    MainForm.ui.qml

                    Rectangle {
                    id: mainContainer

                    property alias lancamentosListView: lancamentosListView
                    property alias rc1: rec1
                    property alias rc2: rec2
                    
                    width: 360
                    height: 640
                    
                    ListView {
                        id: lancamentosListView
                    
                        anchors.fill: parent
                    
                        clip: true
                    
                        spacing: 10
                    }
                    
                    Rectangle {
                        id: rec1
                    }
                    
                    Rectangle {
                        id: rec2
                    }
                    

                    }

                    ModeloLancamentos.qml

                    ListModel {
                    ListElement {
                    valor: "25.000,00"
                    tipo: "Investimento"
                    }
                    }

                    DelegateLancamentos.qml

                    Item {
                    id: delegateItem

                    property Component delegateComponent: delegateComponent
                    property alias removeMouseArea: removeMouseArea
                    
                    Component {
                        id: delegateComponent
                    
                        Row {
                            Column {
                                width: 360 * 0.96 / 8 * 6
                                //width: Screen.width * 0.96 / 8 * 6
                    
                                Text {
                                    text: "<strong>" + "Valor: " + valor + "</strong>"
                                    font.pixelSize: 16
                                }
                                Text {
                                    text: "Tipo: " + tipo
                                    font.pixelSize: 16
                                }
                            }
                    
                            Column {
                                width: 360 * 0.96 / 8
                                //width: Screen.width * 0.96 / 8
                    
                                Image {
                                    id: removeImage
                                    source: "Imagens/remove.png"
                    
                                    width: 35
                    
                                    fillMode: Image.PreserveAspectFit
                    
                                    MouseArea {
                                        id: removeMouseArea
                    
                                        anchors.fill: parent
                                    }
                                }
                            }
                        }
                    }
                    

                    }

                    main.qml

                    Window {
                    visible: true

                    width: 360
                    height: 640
                    
                    maximumHeight: 640
                    minimumHeight: 640
                    
                    maximumWidth: 360
                    minimumWidth: 360
                    
                    title: "InvestmentC-Mobile"
                    
                    MainForm {
                        anchors.fill: parent
                    
                        mainContainer.width: parent.width
                        mainContainer.height: parent.height
                    
                        lancamentosListView.model: modeloLancamentos
                        lancamentosListView.delegate: delegateLancamentos.delegateComponent
                    
                        DelegateLancamentos.removeMouseArea:
                        {
                            modeloLancamentos.remove(index);
                        }
                    }
                    
                    ModeloLancamentos{
                        id: modeloLancamentos
                    }
                    
                    DelegateLancamentos {
                        id: delegateLancamentos
                    }
                    

                    }

                    Att.
                    Guilherme Cortada Dupas

                    P 1 Reply Last reply 10 Jun 2015, 07:06
                    0
                    • G guidupas
                      9 Jun 2015, 12:40

                      @t3685 @p3c0

                      What I really need is that:

                      In MainForm.ui.qml I have two rectangle. I need when i click the mouse area from a delegate component set rec1.visible = false and rec2.visible = true (files below)

                      How can I do that?

                      MainForm.ui.qml

                      Rectangle {
                      id: mainContainer

                      property alias lancamentosListView: lancamentosListView
                      property alias rc1: rec1
                      property alias rc2: rec2
                      
                      width: 360
                      height: 640
                      
                      ListView {
                          id: lancamentosListView
                      
                          anchors.fill: parent
                      
                          clip: true
                      
                          spacing: 10
                      }
                      
                      Rectangle {
                          id: rec1
                      }
                      
                      Rectangle {
                          id: rec2
                      }
                      

                      }

                      ModeloLancamentos.qml

                      ListModel {
                      ListElement {
                      valor: "25.000,00"
                      tipo: "Investimento"
                      }
                      }

                      DelegateLancamentos.qml

                      Item {
                      id: delegateItem

                      property Component delegateComponent: delegateComponent
                      property alias removeMouseArea: removeMouseArea
                      
                      Component {
                          id: delegateComponent
                      
                          Row {
                              Column {
                                  width: 360 * 0.96 / 8 * 6
                                  //width: Screen.width * 0.96 / 8 * 6
                      
                                  Text {
                                      text: "<strong>" + "Valor: " + valor + "</strong>"
                                      font.pixelSize: 16
                                  }
                                  Text {
                                      text: "Tipo: " + tipo
                                      font.pixelSize: 16
                                  }
                              }
                      
                              Column {
                                  width: 360 * 0.96 / 8
                                  //width: Screen.width * 0.96 / 8
                      
                                  Image {
                                      id: removeImage
                                      source: "Imagens/remove.png"
                      
                                      width: 35
                      
                                      fillMode: Image.PreserveAspectFit
                      
                                      MouseArea {
                                          id: removeMouseArea
                      
                                          anchors.fill: parent
                                      }
                                  }
                              }
                          }
                      }
                      

                      }

                      main.qml

                      Window {
                      visible: true

                      width: 360
                      height: 640
                      
                      maximumHeight: 640
                      minimumHeight: 640
                      
                      maximumWidth: 360
                      minimumWidth: 360
                      
                      title: "InvestmentC-Mobile"
                      
                      MainForm {
                          anchors.fill: parent
                      
                          mainContainer.width: parent.width
                          mainContainer.height: parent.height
                      
                          lancamentosListView.model: modeloLancamentos
                          lancamentosListView.delegate: delegateLancamentos.delegateComponent
                      
                          DelegateLancamentos.removeMouseArea:
                          {
                              modeloLancamentos.remove(index);
                          }
                      }
                      
                      ModeloLancamentos{
                          id: modeloLancamentos
                      }
                      
                      DelegateLancamentos {
                          id: delegateLancamentos
                      }
                      

                      }

                      P Offline
                      P Offline
                      p3c0
                      Moderators
                      wrote on 10 Jun 2015, 07:06 last edited by
                      #10

                      @guidupas You can keep a simple bool property, Bind this to the visible property of both the Rectangle. Then when needed update this property to true or false which in turn will modify the visible property of Rectangle.

                      property bool rectVisible : false
                      
                      Rectangle {
                          id: rec1
                          visible: rectVisible
                      }
                      
                      Rectangle {
                          id: rec2
                          visible: !rectVisible
                      }
                      

                      157

                      G 1 Reply Last reply 10 Jun 2015, 20:10
                      0
                      • P p3c0
                        10 Jun 2015, 07:06

                        @guidupas You can keep a simple bool property, Bind this to the visible property of both the Rectangle. Then when needed update this property to true or false which in turn will modify the visible property of Rectangle.

                        property bool rectVisible : false
                        
                        Rectangle {
                            id: rec1
                            visible: rectVisible
                        }
                        
                        Rectangle {
                            id: rec2
                            visible: !rectVisible
                        }
                        
                        G Offline
                        G Offline
                        guidupas
                        wrote on 10 Jun 2015, 20:10 last edited by
                        #11

                        @p3c0

                        But where I declare the property. I tried to declare inside MainForm.ui.qml, inside MainForm at main.qml and inside DelegateLancamentos.qml. In neither of them I could access the property from the MouseArea inside the delegate component.

                        Att.
                        Guilherme Cortada Dupas

                        P 1 Reply Last reply 11 Jun 2015, 06:08
                        0
                        • G guidupas
                          10 Jun 2015, 20:10

                          @p3c0

                          But where I declare the property. I tried to declare inside MainForm.ui.qml, inside MainForm at main.qml and inside DelegateLancamentos.qml. In neither of them I could access the property from the MouseArea inside the delegate component.

                          P Offline
                          P Offline
                          p3c0
                          Moderators
                          wrote on 11 Jun 2015, 06:08 last edited by
                          #12

                          @guidupas
                          main.qml contains Mainform where it then loads the delegate. So declaring a property in main.qml itself will be accessible from MainForm as well as the Delegate. It should work.

                          Apart from that I found some other issues where in you may think its not working:

                          • The ListView in Mainform fills the whole container thus hiding those 2 Rectangle's. Either set z property for those Rects higher than that of ListView or reduce the ListView height.
                          • Provide a width and height for those 2 Rectangle's or else the wont be
                            rendered.

                          157

                          G 1 Reply Last reply 11 Jun 2015, 15:01
                          0
                          • P p3c0
                            11 Jun 2015, 06:08

                            @guidupas
                            main.qml contains Mainform where it then loads the delegate. So declaring a property in main.qml itself will be accessible from MainForm as well as the Delegate. It should work.

                            Apart from that I found some other issues where in you may think its not working:

                            • The ListView in Mainform fills the whole container thus hiding those 2 Rectangle's. Either set z property for those Rects higher than that of ListView or reduce the ListView height.
                            • Provide a width and height for those 2 Rectangle's or else the wont be
                              rendered.
                            G Offline
                            G Offline
                            guidupas
                            wrote on 11 Jun 2015, 15:01 last edited by p3c0 6 Dec 2015, 04:50
                            #13

                            @p3c0 Thank you for all your help. It worked.

                            I am posting here a minimal example just to exemplify for who needs.

                            MainForm.ui.qml

                            import QtQuick 2.4
                            import QtQuick.Controls 1.2
                            import QtQuick.Layouts 1.1
                            
                            Rectangle {
                                id: mainContainer
                            
                                property alias mainContainerA: mainContainer
                                property alias buttonA: button
                                property alias listviewA: listView
                                property alias rect1A: rect1
                                property alias rect2A: rect2
                            
                                width: 600
                                height: 600
                            
                                Button {
                                    id: button
                            
                                    anchors.top: parent.top
                            
                                    text: "Insert value"
                            
                                    height: parent.height * 0.1
                                    width: parent.width
                                }
                            
                                ListView {
                                    id: listView
                            
                                    anchors.top: button.bottom
                            
                                    clip: true
                            
                                    height: parent.height * 0.5
                                    width: parent.width
                                }
                            
                                Rectangle {
                                    id: rect1
                            
                                    visible: true
                            
                                    anchors.top: listView.bottom
                            
                                    width: parent.width
                                    height: parent.height * 0.4
                            
                                    color: "blue"
                                }
                            
                                Rectangle {
                                    id: rect2
                            
                                    visible: false
                            
                                    anchors.top: listView.bottom
                            
                                    width: parent.width
                                    height: parent.height * 0.4
                            
                                    color: "red"
                                }
                            }
                            

                            main.qml

                            import QtQuick 2.4
                            import QtQuick.Window 2.2
                            
                            Window {
                                visible: true
                            
                                width: 600
                                height: 600
                            
                                MainForm {
                                    anchors.fill: parent
                            
                                    listviewA.model: modelM
                                    listviewA.delegate: delegateM.delegateComponent
                            
                                    buttonA.onClicked: {
                                        modelM.append({valor: 100, tipo: 2, tipoIndex: 3});
                                    }
                            
                                    rect1A.visible: delegateM.rect1Visible
                                    rect2A.visible: delegateM.rect2Visible
                                }
                            
                                Delegate {
                                    id: delegateM
                                }
                            
                                Model {
                                    id: modelM
                                }
                            }
                            

                            Delegate.qml

                            import QtQuick 2.4
                            import QtQuick.Controls 1.2
                            import QtQuick.Window 2.2
                            
                            Item {
                                id: delegateItem
                            
                                property Component delegateComponent: delegateComponent
                                property bool rect1Visible: true
                                property bool rect2Visible: false
                            
                                Component {
                                    id: delegateComponent
                            
                                    Row {
                                        height: 53
                            
                                        Column {
                                            width: 600 * 0.96 / 8 * 6
                                            //width: Screen.width * 0.96 / 8 * 6
                            
                            
                                            Text {
                                                text: "<strong>" + "Valor: " + valor + "</strong>"
                                                font.pixelSize: 16
                                            }
                                            Text {
                                                text: "Tipo: " + tipo
                                                font.pixelSize: 16
                                            }
                                        }
                            
                                        Column {
                                            width: 600 * 0.96 / 8
                                            //width: Screen.width * 0.96 / 8
                            
                                            Rectangle {
                                                color: "grey"
                                                width: 50
                                                height: 50
                                                MouseArea {
                                                    id: editMouseArea
                            
                                                    anchors.fill: parent
                            
                                                    onClicked:
                                                    {
                                                        rect1Visible = true;
                                                        rect2Visible = false;
                                                    }
                                                }
                                            }
                            
                                        }
                            
                                        Column {
                                            width: 600 * 0.96 / 8
                                            //width: Screen.width * 0.96 / 8
                            
                                            Rectangle {
                                                color: "darkred"
                                                width: 50
                                                height: 50
                                                MouseArea {
                                                    id: removeMouseArea
                            
                                                    anchors.fill: parent
                            
                                                    onClicked:
                                                    {
                                                        rect1Visible = false;
                                                        rect2Visible = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            

                            Model.qml

                            import QtQuick 2.0
                            
                            ListModel {
                                
                            }
                            

                            Att.
                            Guilherme Cortada Dupas

                            P 1 Reply Last reply 12 Jun 2015, 04:49
                            0
                            • G guidupas
                              11 Jun 2015, 15:01

                              @p3c0 Thank you for all your help. It worked.

                              I am posting here a minimal example just to exemplify for who needs.

                              MainForm.ui.qml

                              import QtQuick 2.4
                              import QtQuick.Controls 1.2
                              import QtQuick.Layouts 1.1
                              
                              Rectangle {
                                  id: mainContainer
                              
                                  property alias mainContainerA: mainContainer
                                  property alias buttonA: button
                                  property alias listviewA: listView
                                  property alias rect1A: rect1
                                  property alias rect2A: rect2
                              
                                  width: 600
                                  height: 600
                              
                                  Button {
                                      id: button
                              
                                      anchors.top: parent.top
                              
                                      text: "Insert value"
                              
                                      height: parent.height * 0.1
                                      width: parent.width
                                  }
                              
                                  ListView {
                                      id: listView
                              
                                      anchors.top: button.bottom
                              
                                      clip: true
                              
                                      height: parent.height * 0.5
                                      width: parent.width
                                  }
                              
                                  Rectangle {
                                      id: rect1
                              
                                      visible: true
                              
                                      anchors.top: listView.bottom
                              
                                      width: parent.width
                                      height: parent.height * 0.4
                              
                                      color: "blue"
                                  }
                              
                                  Rectangle {
                                      id: rect2
                              
                                      visible: false
                              
                                      anchors.top: listView.bottom
                              
                                      width: parent.width
                                      height: parent.height * 0.4
                              
                                      color: "red"
                                  }
                              }
                              

                              main.qml

                              import QtQuick 2.4
                              import QtQuick.Window 2.2
                              
                              Window {
                                  visible: true
                              
                                  width: 600
                                  height: 600
                              
                                  MainForm {
                                      anchors.fill: parent
                              
                                      listviewA.model: modelM
                                      listviewA.delegate: delegateM.delegateComponent
                              
                                      buttonA.onClicked: {
                                          modelM.append({valor: 100, tipo: 2, tipoIndex: 3});
                                      }
                              
                                      rect1A.visible: delegateM.rect1Visible
                                      rect2A.visible: delegateM.rect2Visible
                                  }
                              
                                  Delegate {
                                      id: delegateM
                                  }
                              
                                  Model {
                                      id: modelM
                                  }
                              }
                              

                              Delegate.qml

                              import QtQuick 2.4
                              import QtQuick.Controls 1.2
                              import QtQuick.Window 2.2
                              
                              Item {
                                  id: delegateItem
                              
                                  property Component delegateComponent: delegateComponent
                                  property bool rect1Visible: true
                                  property bool rect2Visible: false
                              
                                  Component {
                                      id: delegateComponent
                              
                                      Row {
                                          height: 53
                              
                                          Column {
                                              width: 600 * 0.96 / 8 * 6
                                              //width: Screen.width * 0.96 / 8 * 6
                              
                              
                                              Text {
                                                  text: "<strong>" + "Valor: " + valor + "</strong>"
                                                  font.pixelSize: 16
                                              }
                                              Text {
                                                  text: "Tipo: " + tipo
                                                  font.pixelSize: 16
                                              }
                                          }
                              
                                          Column {
                                              width: 600 * 0.96 / 8
                                              //width: Screen.width * 0.96 / 8
                              
                                              Rectangle {
                                                  color: "grey"
                                                  width: 50
                                                  height: 50
                                                  MouseArea {
                                                      id: editMouseArea
                              
                                                      anchors.fill: parent
                              
                                                      onClicked:
                                                      {
                                                          rect1Visible = true;
                                                          rect2Visible = false;
                                                      }
                                                  }
                                              }
                              
                                          }
                              
                                          Column {
                                              width: 600 * 0.96 / 8
                                              //width: Screen.width * 0.96 / 8
                              
                                              Rectangle {
                                                  color: "darkred"
                                                  width: 50
                                                  height: 50
                                                  MouseArea {
                                                      id: removeMouseArea
                              
                                                      anchors.fill: parent
                              
                                                      onClicked:
                                                      {
                                                          rect1Visible = false;
                                                          rect2Visible = true;
                                                      }
                                                  }
                                              }
                                          }
                                      }
                                  }
                              }
                              

                              Model.qml

                              import QtQuick 2.0
                              
                              ListModel {
                                  
                              }
                              
                              P Offline
                              P Offline
                              p3c0
                              Moderators
                              wrote on 12 Jun 2015, 04:49 last edited by
                              #14

                              @guidupas You're Welcome :)
                              Use ``` (3 backticks) instead of [Code] when posting code here. It follows markdown language syntax. I'll edit it for now.

                              157

                              1 Reply Last reply
                              0

                              5/14

                              8 Jun 2015, 17:35

                              topic:navigator.unread, 9
                              • Login

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