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
QtWS25 Last Chance

send signal from ListElement to button

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 540 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.
  • amir.sanaatA Offline
    amir.sanaatA Offline
    amir.sanaat
    wrote on 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
            }
        }
    
    
    }
    
    
    Gojir4G 1 Reply Last reply
    0
    • Gojir4G Gojir4

      @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()
          }
      }
      
      amir.sanaatA Offline
      amir.sanaatA Offline
      amir.sanaat
      wrote on last edited by
      #5

      @Gojir4 Thanks my friend

      1 Reply Last reply
      0
      • amir.sanaatA amir.sanaat

        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
                }
            }
        
        
        }
        
        
        Gojir4G Offline
        Gojir4G Offline
        Gojir4
        wrote on 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

        amir.sanaatA 1 Reply Last reply
        0
        • Gojir4G Gojir4

          @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

          amir.sanaatA Offline
          amir.sanaatA Offline
          amir.sanaat
          wrote on 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.

          Gojir4G 1 Reply Last reply
          0
          • amir.sanaatA amir.sanaat

            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.

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on 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()
                }
            }
            
            amir.sanaatA 1 Reply Last reply
            0
            • Gojir4G Gojir4

              @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()
                  }
              }
              
              amir.sanaatA Offline
              amir.sanaatA Offline
              amir.sanaat
              wrote on last edited by
              #5

              @Gojir4 Thanks my friend

              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