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. send signal from ListElement to button
Forum Updated to NodeBB v4.3 + New Features

send signal from ListElement to button

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 551 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    amir.sanaat
    wrote on 26 Aug 2018, 11:36 last edited by
    #1

    hello
    i have two popup components ( popid1 & popid2) which i want to opens by buttons in a GridView.
    the data of this button stored in a ListMode and ListElement.each element have a parameter called "nambero". i wanna by clicking on each button diffrent popup open.

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.0
    import QtQuick.Controls 2.2
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        GridView {
            id: gridView
            width: 88
            height: 79
            transformOrigin: Item.Center
            contentHeight: 0
            cellHeight: 40
            delegate: Item {
                x: 5
                height: 50
                Column {
                    x: 202
                    y: 157
                    width: 160
                    height: 206
                    Button {
                        id: button
                        text: qsTr("Button")
                        width: 30
                        height:30
                        onClicked: popid+numbero.open()
                    }
    
                    spacing: 5
                }
            }
            cellWidth: 40
            model: ListModel {
                ListElement {
                    name: "Grey"
                    colorCode: "grey"
                    numbero:1
                }
    
                ListElement {
                    name: "Red"
                    colorCode: "red"
                    numbero:2
    
                }
    
                ListElement {
                    name: "Blue"
                    colorCode: "blue"
                    numbero:3
    
                }
    
                ListElement {
                    name: "Green"
                    colorCode: "green"
                }
            }
            Popup {
    
                id:popid1
                width: parent.width / 1.2
                height: parent.height / 1.2
                x: (parent.width - width) / 2
                y: (parent.height - height) / 2
                dim: true
                modal: true
                focus: true
                closePolicy: Popup.Popup.CloseOnPressOutside | Popup.CloseOnPressOutsideParent
            }
    
            Popup {
    
                id:popid2
                width: parent.width /2
                height: parent.height / 2
                x: (parent.width - width) / 2
                y: (parent.height - height) / 2
                dim: true
                modal: true
                focus: true
                closePolicy: Popup.Popup.CloseOnPressOutside | Popup.CloseOnPressOutsideParent
            }
        }
    
    
    }
    
    
    G 1 Reply Last reply 26 Aug 2018, 11:43
    0
    • G Gojir4
      26 Aug 2018, 11:55

      @amir.sanaat Ok, was a long time I didn't code in QML, sorry. May be a switch can make the job. That's not very elegant but I think it will work. I don't have anything else yet.

      onClicked:{
          switch(numbero){
              1: popid1.open()
              2: popid2.open()
          }
      }
      
      A Offline
      A Offline
      amir.sanaat
      wrote on 26 Aug 2018, 12:36 last edited by
      #5

      @Gojir4 Thanks my friend

      1 Reply Last reply
      0
      • A amir.sanaat
        26 Aug 2018, 11:36

        hello
        i have two popup components ( popid1 & popid2) which i want to opens by buttons in a GridView.
        the data of this button stored in a ListMode and ListElement.each element have a parameter called "nambero". i wanna by clicking on each button diffrent popup open.

        import QtQuick 2.9
        import QtQuick.Window 2.2
        import QtQuick.Layouts 1.0
        import QtQuick.Controls 2.2
        Window {
            visible: true
            width: 640
            height: 480
            title: qsTr("Hello World")
        
            GridView {
                id: gridView
                width: 88
                height: 79
                transformOrigin: Item.Center
                contentHeight: 0
                cellHeight: 40
                delegate: Item {
                    x: 5
                    height: 50
                    Column {
                        x: 202
                        y: 157
                        width: 160
                        height: 206
                        Button {
                            id: button
                            text: qsTr("Button")
                            width: 30
                            height:30
                            onClicked: popid+numbero.open()
                        }
        
                        spacing: 5
                    }
                }
                cellWidth: 40
                model: ListModel {
                    ListElement {
                        name: "Grey"
                        colorCode: "grey"
                        numbero:1
                    }
        
                    ListElement {
                        name: "Red"
                        colorCode: "red"
                        numbero:2
        
                    }
        
                    ListElement {
                        name: "Blue"
                        colorCode: "blue"
                        numbero:3
        
                    }
        
                    ListElement {
                        name: "Green"
                        colorCode: "green"
                    }
                }
                Popup {
        
                    id:popid1
                    width: parent.width / 1.2
                    height: parent.height / 1.2
                    x: (parent.width - width) / 2
                    y: (parent.height - height) / 2
                    dim: true
                    modal: true
                    focus: true
                    closePolicy: Popup.Popup.CloseOnPressOutside | Popup.CloseOnPressOutsideParent
                }
        
                Popup {
        
                    id:popid2
                    width: parent.width /2
                    height: parent.height / 2
                    x: (parent.width - width) / 2
                    y: (parent.height - height) / 2
                    dim: true
                    modal: true
                    focus: true
                    closePolicy: Popup.Popup.CloseOnPressOutside | Popup.CloseOnPressOutsideParent
                }
            }
        
        
        }
        
        
        G Offline
        G Offline
        Gojir4
        wrote on 26 Aug 2018, 11:43 last edited by
        #2

        @amir.sanaat Hi, I think you could store the reference on the popup in you ListElement:

        onClicked: popup.open()
        ...
        ListElement {
            name: "Grey"
            colorCode: "grey"
            numbero:1
            popup: popid1
        }
        

        Another solution could be having only one popup and then using a loader to display the GUI according to numbero

        A 1 Reply Last reply 26 Aug 2018, 11:47
        0
        • G Gojir4
          26 Aug 2018, 11:43

          @amir.sanaat Hi, I think you could store the reference on the popup in you ListElement:

          onClicked: popup.open()
          ...
          ListElement {
              name: "Grey"
              colorCode: "grey"
              numbero:1
              popup: popid1
          }
          

          Another solution could be having only one popup and then using a loader to display the GUI according to numbero

          A Offline
          A Offline
          amir.sanaat
          wrote on 26 Aug 2018, 11:47 last edited by
          #3

          Dear @Gojir4 thank you for snap reply
          the way you said dosent work and i faced with "ListElement: cannot use script for property value" error.

          G 1 Reply Last reply 26 Aug 2018, 11:55
          0
          • A amir.sanaat
            26 Aug 2018, 11:47

            Dear @Gojir4 thank you for snap reply
            the way you said dosent work and i faced with "ListElement: cannot use script for property value" error.

            G Offline
            G Offline
            Gojir4
            wrote on 26 Aug 2018, 11:55 last edited by
            #4

            @amir.sanaat Ok, was a long time I didn't code in QML, sorry. May be a switch can make the job. That's not very elegant but I think it will work. I don't have anything else yet.

            onClicked:{
                switch(numbero){
                    1: popid1.open()
                    2: popid2.open()
                }
            }
            
            A 1 Reply Last reply 26 Aug 2018, 12:36
            0
            • G Gojir4
              26 Aug 2018, 11:55

              @amir.sanaat Ok, was a long time I didn't code in QML, sorry. May be a switch can make the job. That's not very elegant but I think it will work. I don't have anything else yet.

              onClicked:{
                  switch(numbero){
                      1: popid1.open()
                      2: popid2.open()
                  }
              }
              
              A Offline
              A Offline
              amir.sanaat
              wrote on 26 Aug 2018, 12:36 last edited by
              #5

              @Gojir4 Thanks my friend

              1 Reply Last reply
              0

              4/5

              26 Aug 2018, 11:55

              • Login

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