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. RE: QML id usage
Forum Updated to NodeBB v4.3 + New Features

RE: QML id usage

Scheduled Pinned Locked Moved Solved QML and Qt Quick
20 Posts 5 Posters 3.8k 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.
  • 6thC6 Offline
    6thC6 Offline
    6thC
    wrote on last edited by
    #10

    What about creating some objects states (and maybe transitions too)?
    https://wiki.qt.io/QML_States_Controlling
    instead of messing with the insides of another class you are utilizing a defined state/interface and you design your module to handle the various state configurations/behaviors expected of it.

    Naveen_DN 1 Reply Last reply
    0
    • 6thC6 6thC

      What about creating some objects states (and maybe transitions too)?
      https://wiki.qt.io/QML_States_Controlling
      instead of messing with the insides of another class you are utilizing a defined state/interface and you design your module to handle the various state configurations/behaviors expected of it.

      Naveen_DN Offline
      Naveen_DN Offline
      Naveen_D
      wrote on last edited by
      #11

      @6thC I am using voice recognition over here based on the voice i am doing some changes is it possible using states ???

      Naveen_D

      1 Reply Last reply
      0
      • 6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by 6thC
        #12

        Well, I don't know the conditions to change states, that would be up to you. But sure. I think. It's possible I misunderstand or didn't read what you want enough.

        I use states for changing the gui, not images but color and animations based on sensor's numeric values.

        states:
          [
              State { name: "inSpec";
                  PropertyChanges { target: indicator; color: hudGreen;  }     
              },
              State { name: "warning";
                  PropertyChanges { target: indicator; color: "gold";        }
              },
              State { name: "maximum";
                  PropertyChanges { target: indicator; color: "red";         }
              }
        
          transitions: [
              Transition {
                  from: "maximum"
                  to: "inSpec"
                  SequentialAnimation {
                      loops: 1;
                      ColorAnimation { duration: 300; from: "red";        to: hudGreen; }
                      ColorAnimation { duration: 300; from: hudGreen; to: "transparent";}
                  }
              },
              Transition {
                  from: "warning"
                  to: "inSpec"
                  ColorAnimation { target: root; duration: 300}
                  ColorAnimation { duration: 300; from: "red";        to: hudGreen; }
                  ColorAnimation { duration: 300; from: hudGreen; to: "transparent";}
              },
        ...
        

        And I use this in a method where I pass a control as an argument (with the states and transitions in it) and the sensor value like:

        function adjustState(control, value){
        ... inSpec expression 
                      control.state =  "inSpec";
        ... warning expression 
                      control.state =  "warning";
        ... maximum expression 
                      control.state =  "maximum";
        
        1 Reply Last reply
        0
        • Naveen_DN Offline
          Naveen_DN Offline
          Naveen_D
          wrote on last edited by
          #13

          I tried using property aliasing...but no output can anyone pls guide me further in this matter....it would be helpful.

          Naveen_D

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #14

            @Naveen_D You need to provide a very minimal complete code of your application which can reproduce the problem. This would be more useful for others to understand.

            157

            Naveen_DN 1 Reply Last reply
            0
            • p3c0P p3c0

              @Naveen_D You need to provide a very minimal complete code of your application which can reproduce the problem. This would be more useful for others to understand.

              Naveen_DN Offline
              Naveen_DN Offline
              Naveen_D
              wrote on last edited by
              #15

              @p3c0 ya sure here is the code,

              main.qml

              import QtQuick 2.7
              import QtQuick.Window 2.2
              import QtQuick.Layouts 1.2
              import QtQuick 2.5
              
              
              Window {
                  //    flags: Qt.FramelessWindowHint
              
                  title: qsTr("Infotainment")
                  width: (Screen.width/4)+200
                  height: (Screen.height/4)
                  visible: true
              
                  ExampleRect1
                  {
                      id: rect1id
                      visible: false
                  }
              
                  ExampleRect2
                  {
                      id: rect2id
                      visible: false
                  }
                  Row
                  {
                      id: rectrow
                      spacing: 100
                      anchors.centerIn: parent
                      Rectangle {
                          id: myRect
                          width: 150; height: 100
                          color: "transparent"
                          border.color: "black"
                          Text {
                              id: rect1text
                              text: qsTr("Rectangle1")
                              font.bold: true
                              font.pixelSize: 24
                              color: "red"
                              anchors.centerIn: parent
                          }
              
                          MouseArea {
                              id: mouseArea
                              anchors.fill: parent
                              onClicked: {
                                  rect1id.visible= true
                                  rectrow.visible = false
                                  rect2id.visible= false
                              }
                          }
                      }
              
                      Rectangle {
                          id: myRect2
                          width: 150; height: 100
                          color: "transparent"
                          border.color: "black"
                          Text {
                              id: rect2text
                              text: qsTr("Rectangle2")
                              font.bold: true
                              font.pixelSize: 24
                              color: "blue"
                              anchors.centerIn: parent
                          }
              
                          MouseArea {
                              id: mouseArea2
                              anchors.fill: parent
                              onClicked: {
                                  rect2id.visible= true
                                  rectrow.visible= false
                                  rect1id.visible= false
                              }
                          }
                      }
                  }
              }
              
              

              ExampleRect1.qml

              import QtQuick 2.0
              import QtQuick.Window 2.2
              
              Rectangle{
                  id: mainRect
                  width: (Screen.width/4)+200
                  height: (Screen.height/4)
                  visible: false
              
                  property alias imgSource : img.source
              
              
                  Rectangle{
                     id: imgRect
                     implicitHeight: 100; implicitWidth: 150
                     anchors.centerIn: parent
              
                     Image {
                         id: img
                         source: "qrc:/PlayIcon.png"
                     }
                  }
              }
              
              

              RectExample2.qml

              import QtQuick 2.0
              import QtQuick.Window 2.2
              import QtQuick.Layouts 1.2
              import QtQuick 2.5
              
              Rectangle{
                  id :mainRect
                  width: (Screen.width/4)+200
                  height: (Screen.height/4)
              
                  ExampleRect1{
                      id:exampleRect1Object
                  }
              
                  Rectangle{
                      id: voicerect
                      implicitHeight: 100; implicitWidth: 150
                      anchors.centerIn: parent
                      color: "red"
              
                      Text {
                          id: voiceText
                          text: qsTr("Voice Recognition")
                          anchors.centerIn: parent
                          font.pixelSize: 18
                      }
              
                      MouseArea{
                          id: voicemousearea
                          anchors.fill: parent
                          onClicked: {
                              rect1id.visible =true
                              exampleRect1Object.imgSource= "qrc:/pauseIcon.png"
                              mainRect.visible= false
                          }
                      }
                  }
              }
              
              

              Naveen_D

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #16

                @Naveen_D Ok. And what do you require in this example ?

                157

                Naveen_DN 1 Reply Last reply
                0
                • p3c0P p3c0

                  @Naveen_D Ok. And what do you require in this example ?

                  Naveen_DN Offline
                  Naveen_DN Offline
                  Naveen_D
                  wrote on last edited by
                  #17

                  @p3c0
                  In the above example, in ExampleRect2.qml i have created an object of ExampleRect1.qml

                  onClicked: {
                  rect1id.visible =true
                  exampleRect1Object.imgSource= "qrc:/pauseIcon.png"
                  mainRect.visible= false
                  }

                  using that object i am changing the image set in exampleRect1.qml but the image remains same, it will not change...

                  Naveen_D

                  1 Reply Last reply
                  0
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #18

                    @Naveen_D AFAICS you are creating 2 instances of ExampleRect1, one is in main.qml and other is in ExampleRect2.qml and you are trying to update this instance instead of one in main.qml

                    157

                    Naveen_DN 1 Reply Last reply
                    0
                    • p3c0P p3c0

                      @Naveen_D AFAICS you are creating 2 instances of ExampleRect1, one is in main.qml and other is in ExampleRect2.qml and you are trying to update this instance instead of one in main.qml

                      Naveen_DN Offline
                      Naveen_DN Offline
                      Naveen_D
                      wrote on last edited by
                      #19

                      @p3c0 Ya i got the output...thanks

                      Naveen_D

                      1 Reply Last reply
                      0
                      • p3c0P Offline
                        p3c0P Offline
                        p3c0
                        Moderators
                        wrote on last edited by
                        #20

                        @Naveen_D Great!

                        157

                        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