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. Switch that controls other qml files
Forum Updated to NodeBB v4.3 + New Features

Switch that controls other qml files

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

    Using PySide2, Qt Quick Controls, and Py Creator:

    In my Project/qml/pages/settingsPage.qml, I created a switch:

            Rectangle {
                id: rectangle1
                width: 220
                height: 60
                visible: true
                color: "#2c303b"
                radius: 10
                border.width: 0
                Layout.fillHeight: false
                Layout.alignment: Qt.AlignLeft | Qt.AlignTop
                Layout.fillWidth: true
                anchors.leftMargin: 20
                anchors.topMargin: 20
    
    
    
                Switch {
                    id: mySwitch
                    anchors.left: parent.left
                    anchors.top: parent.top
                    anchors.bottom: parent.bottom
                    display: AbstractButton.IconOnly
                    spacing: 20
                    font.wordSpacing: 0
                    rightPadding: 0
                    padding: 0
                    font.pointSize: 15
    
                    onToggled: {
                    //backend.
    
                    }
    
                    Label {
                        id: labelTextName1
                        x: 120
                        width: 200
                        color: "#e8e9ec"
                        text: qsTr("Switch")
                        anchors.right: parent.right
                        anchors.top: parent.top
                        anchors.bottom: parent.bottom
                        horizontalAlignment: Text.AlignHCenter
                        verticalAlignment: Text.AlignVCenter
                        anchors.rightMargin: -170
                        font.pointSize: 14
    
                    }
                }
            }
    

    Inside the onToggled for the switch, I want to create a property in my project/qml/pages/homePage.qml and change the color of the background in homePage.qml. What function do I need to create inside the main.py.

    homePage.qml:

    Item {
    id: item1
    Rectangle {
    id: rectangle
    color: "#2c313c"
    //want to change this color
    anchors.fill: parent
    ...
    }
    }
    
    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @final_software said in Switch that controls other qml files:

      homePage.qml

      Where is your instance defined? You have to instantiate an object before you use it or manipulate it.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • F Offline
        F Offline
        final_software
        wrote on last edited by
        #3

        I made little changes to my code so that:

        In the settingsPage.qml file, I have this inside of onToggled:
        backend.switchValue = toggled

        In the homePage.qml file, I have this inside one of the rectangles I've created:

        visible: backend.switchValue()

        Lastly, in main.py file:
        customTitleBar = Signal(bool)
        @Slot()
        def switchValue(self):
        return customTitleBar.isToggled

        What am I doing wrong?

        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