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 emit signal with a button
Forum Updated to NodeBB v4.3 + New Features

how to emit signal with a button

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 394 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.
  • S Offline
    S Offline
    San12
    wrote on last edited by
    #1

    this is my first time using slider and i'm learning with this exemple . i'm trying to set up a slider controlled with 3 button , i have made 3 signal to emit slider state but the probleme is the button are clickable and they send no signal to slider

    VoletCommande.qml
    Item {
        id: voletCommande
    
        signal shutterToMove(bool value)
        signal shutterToStop()
        signal shutterToSetAt(int value) //value(0 to 100)
    
    
        property int iSliderVoletMoving : 0
        property int iSliderValue : 25
    
    
        property string textVolet : ""
    
    
        property int fontSize : 10
    
    
        width: (parent.width-10) / 3
        height: parent.height - 15
    
    
    
    
    
        Rectangle
        {
            anchors.fill: parent
            color: "transparent"
            border.color: "light blue"
            border.width: 0.5
            Text
             {
                text: textVolet
                anchors.top: parent.top
                anchors.topMargin: 2
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.leftMargin: 2
                color: "gray"
    
                font.pointSize: fontSize
             }
            Rectangle
            {
                width: parent.width
                height: parent.height*2/3 - 1.5*fontSize
                anchors.top: parent.top
                anchors.topMargin: 1.5*fontSize
                Image
                {
                    id:imgVoletDown
                    source: (iSliderVoletMoving == 2)? "qrc:/ShutterDownOn.png" : "qrc:/ShutterDownOff.png"
                    width: parent.width / 3
                    height: parent.height
                    anchors.left: parent.left
    
                    MouseArea
                    {
                        anchors.fill: parent;
                        onClicked: {
                            shutterToMove(false);
                        }
                    }
    
                }
                }
                Image
                {
                    id:imgVoletStop
                    source: (iSliderVoletMoving == 0) ? "qrc:/ShutterStopOn.png" :"qrc:/ShutterStopOff.png"
                    width: parent.width / 3
                    height: parent.height
                    anchors.left: imgVoletDown.right
                    MouseArea
                    {
                        anchors.fill: parent;
                        onClicked: {
                            shutterToStop();
                        }
    
                    }
                 }
                Image
                {
                    id:imgVoletUp
                    source: (iSliderVoletMoving == 1) ? "qrc:/ShutterUpOn.png" : "qrc:/ShutterUpOff.png"
                    width: parent.width / 3
                    height: parent.height
                    anchors.left: imgVoletStop.right
    
                    MouseArea
                    {
                        anchors.fill: parent;
                        onClicked: {
                            shutterToMove(true);
    
    
                        }
                    }
    
                }
    
            }
            Rectangle
            {
                width: parent.width
                height: parent.height/3
                anchors.bottom: parent.bottom
    
    
                Slider
                {
                    id : sliderVolet
                    anchors.top: parent.top
                    anchors.verticalCenter: parent.verticalCenter
    
                    from: 0.0
                    value: (iSliderValue / 100)
                    to: parent.width * 3/4
                    snapMode : Slider.SnapAlways
                    stepSize : (to-from) / 20
                    onMoved:
                        {
                            stutterToSetAt(100 * sliderVolet.value / sliderVolet.to);
                        }
                }
                Text {
                    text: iSliderValue +"%"
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left : sliderVolet.right
                    anchors.leftMargin: 2
                    color: "light blue"
    
                    font.pointSize: fontSize*1.2
                }
            }
    }
    
    Volet.qml
    
    Item {
        id : voletsTab
    
        signal shutterToMove1(bool value) 
        signal shutterToStop1()
        signal stutterToSetAt1(int value) //value(0 to 100)
    
        signal shutterToMove2(bool value) // true : up, false : down
        signal shutterToStop2()
        signal stutterToSetAt2(int value) //value(0 to 100)
    
        signal shutterToMove3(bool value) // true : up, false : down
        signal shutterToStop3()
        signal stutterToSetAt3(int value) //value(0 to 100)
    
        width: parent.width
        height: parent.height
        anchors.left: parent.left
        anchors.leftMargin: 5
        anchors.top: parent.top
        anchors.topMargin: 5
        property int fontSize : 10
    
        property int nbOfVolets : 1
    
        property int iSliderVolet1Moving : 0
        property int iSliderVolet1Value : 0 // en %
        property string textVolet1 : "VR1"
    
        property int iSliderVolet2Moving : 0
        property int iSliderVolet2Value : 0 // en %
        property string textVolet2 : "VR2"
    
        property int iSliderVolet3Moving : 0
        property int iSliderVolet3Value : 0 // en %
        property string textVolet3 : "VR3"
    
    
    
        Rectangle
        {
            anchors.fill: parent
            color: "transparent"
            border.color: "transparent"
            border.width: 0.5
            Text
             {
                text: qsTr("VOLETS")
                anchors.top: parent.top
                anchors.topMargin: 5
                anchors.left: parent.left
                anchors.leftMargin: 5
                color: "gray"
    
                font.pointSize: fontSize
             }
    
            VoletCommande
            {
                id : voletCommande1
                textVolet : textVolet1
    
                iSliderVoletMoving : iSliderVolet1Moving
                iSliderValue : iSliderVolet1Value // en %
    
                anchors.top: parent.top
                anchors.topMargin: 15
                anchors.left: parent.left
                anchors.leftMargin: (nbOfVolets>=3) ? 5 : parent.width /(nbOfVolets*3)
    
                onShutterToMove:{shutterToMove1(value);}
                onShutterToStop:{shutterToStop1();}
                onStutterToSetAt:{stutterToSetAt1(value);}
            }
    
            VoletCommande
            {
                id : voletCommande2
                textVolet : textVolet2
                iSliderVoletMoving : iSliderVolet2Moving
                iSliderValue : iSliderVolet2Value // en %
    
                anchors.top: parent.top
                anchors.topMargin: 15
                anchors.left: voletCommande1.right
                anchors.leftMargin: 5
                visible : (nbOfVolets>=2) ? true : false
    
                onShutterToMove:{shutterToMove2(value);}
                onShutterToStop:{shutterToStop2();}
                onStutterToSetAt:{stutterToSetAt2(value);}
            }
    
            VoletCommande
            {
                id : voletCommande3
                textVolet : textVolet3
                iSliderVoletMoving : iSliderVolet3Moving
                iSliderValue : iSliderVolet3Value // en %
    
                anchors.top: parent.top
                anchors.topMargin: 15
                anchors.left: voletCommande2.right
                anchors.leftMargin: 5
                visible : (nbOfVolets>=3) ? true : false
    
                onShutterToMove:{shutterToMove3(value);}
                onShutterToStop:{shutterToStop3();}
                onStutterToSetAt:{stutterToSetAt3(value);}
            }
    
    
        }
    }
    `Please heeelp``
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please provide a minimal compilable example.

      You should cut down the amount of code between your two classes to the bare minimum to have it working first.

      You also seem to try to assign signals to other signals in an unrelated class.

      From the looks of it, you should first cleanup your VoletCommand object to work properly.

      Finally, boolean values to represent whether your something should move up or down is a bad idea. Use an enumeration so its explicit and you don't have to re-read your whole code to find out in which direction the thing should move.
      Did you also follow the Signal and Handler Event System docuementation ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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