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. Setting the visible property to false does not hide elements

Setting the visible property to false does not hide elements

Scheduled Pinned Locked Moved Solved QML and Qt Quick
visibleqmlpage
4 Posts 2 Posters 318 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.
  • S Offline
    S Offline
    Saviz
    wrote on 10 Jan 2025, 03:54 last edited by
    #1

    I need to create a page element that represents a page or tab in my application. This page should be able to hold multiple elements (e.g., Buttons, ComboBoxes, Text elements). To achieve this, I designed the page element to include a ScrollView, allowing vertical stacking and scrolling of its contents.

    Here is the code:

    Item {
        id: root
    
        default property alias content: columnLayout.data
        property alias pageTitle: titleText.text
    
        implicitWidth: 300
        implicitHeight: 300
    
        Rectangle {
            anchors.fill: parent
            color: "white"
    
            // ScrollView to enable vertical scrolling for the page.
            ScrollView {
                anchors.fill: parent
    
                contentWidth: -1 // Disable horizontal scrolling
                contentHeight: columnLayout.height
    
                ColumnLayout {
                    id: columnLayout
    
                    anchors.fill: parent
                    clip: true
    
                    // Title text for the page.
                    Text {
                        id: titleText
                        horizontalAlignment: Text.AlignLeft
                        verticalAlignment: Text.AlignVCenter
                        color: "black"
                    }
                }
            }
        }
    }
    

    This implementation works well, and I can add as many elements as I want. However, there's an issue when I attempt to set the visible property of the page to false. It should make the entire page and all its elements invisible, but that isn't happening.

    Here is how I use it:

    CustomPage {
        anchors.fill: parent
    
        visible: false // This should make sure the entire page is not visible anymore...
        
        // Many elements are placed here...
        
        Button {
            Layout.preferredWidth: 120
            Layout.preferredHeight: 35
    
            text: qsTr("Cilck me")
        }
        
        // Many elements are placed here...
    }
    

    I am not sure why this is not working.

    Qt version: 6.7.3
    Operating System: Windows 10 64-bit

    1 Reply Last reply
    0
    • M Markkyboy
      10 Jan 2025, 10:02

      Works fine for me. I put CustomPage.qml into a separate folder (components).

      I don't have access to ScrollView and so changed it out for Flickable, as I know flickable properties for contentWidth and contentHeight are available.

      I removed "clip: true" from "columnLayout" in CustomPage as the button was not visible to me.

      I'm still using Qt5.15.2 on SailfishOS SDK under Windows 10 64bit, so take what I'm reporting with a pinch of salt.

      Regardless, I can now set the visible property to true or false without a problem.

      S Offline
      S Offline
      Saviz
      wrote on 10 Jan 2025, 18:23 last edited by
      #3

      @Markkyboy Unfortunately, this method didn’t work for me, and I’m genuinely unsure why. However, I found an alternative solution to address the issue.

      I created an alias property that controls the visibility of my ScrollView. By doing so, the entire page becomes hidden when necessary.

      Here is the code:

      Item {
          id: root
      
          default property alias content: columnLayout.data
          property alias pageTitle: titleText.text
          property alias contentVisible: scrollView.visible // Set this to 'false' when using component.
      
          implicitWidth: 300
          implicitHeight: 300
      
          Rectangle {
              anchors.fill: parent
              color: "white"
      
              // ScrollView to enable vertical scrolling for the page.
              ScrollView {
                  id: scrollView
                  anchors.fill: parent
      
                  contentWidth: -1 // Disable horizontal scrolling
                  contentHeight: columnLayout.height
      
                  ColumnLayout {
                      id: columnLayout
      
                      anchors.fill: parent
                      clip: true
      
                      // Title text for the page.
                      Text {
                          id: titleText
                          horizontalAlignment: Text.AlignLeft
                          verticalAlignment: Text.AlignVCenter
                          color: "black"
                      }
                  }
              }
          }
      }
      

      This works for now. But, I still don't understand why the normal one does not work. Does this have to do with something in version 6.7.3?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Markkyboy
        wrote on 10 Jan 2025, 10:02 last edited by
        #2

        Works fine for me. I put CustomPage.qml into a separate folder (components).

        I don't have access to ScrollView and so changed it out for Flickable, as I know flickable properties for contentWidth and contentHeight are available.

        I removed "clip: true" from "columnLayout" in CustomPage as the button was not visible to me.

        I'm still using Qt5.15.2 on SailfishOS SDK under Windows 10 64bit, so take what I'm reporting with a pinch of salt.

        Regardless, I can now set the visible property to true or false without a problem.

        Don't just sit there standing around, pick up a shovel and sweep up!

        I live by the sea, not in it.

        S 1 Reply Last reply 10 Jan 2025, 18:23
        0
        • M Markkyboy
          10 Jan 2025, 10:02

          Works fine for me. I put CustomPage.qml into a separate folder (components).

          I don't have access to ScrollView and so changed it out for Flickable, as I know flickable properties for contentWidth and contentHeight are available.

          I removed "clip: true" from "columnLayout" in CustomPage as the button was not visible to me.

          I'm still using Qt5.15.2 on SailfishOS SDK under Windows 10 64bit, so take what I'm reporting with a pinch of salt.

          Regardless, I can now set the visible property to true or false without a problem.

          S Offline
          S Offline
          Saviz
          wrote on 10 Jan 2025, 18:23 last edited by
          #3

          @Markkyboy Unfortunately, this method didn’t work for me, and I’m genuinely unsure why. However, I found an alternative solution to address the issue.

          I created an alias property that controls the visibility of my ScrollView. By doing so, the entire page becomes hidden when necessary.

          Here is the code:

          Item {
              id: root
          
              default property alias content: columnLayout.data
              property alias pageTitle: titleText.text
              property alias contentVisible: scrollView.visible // Set this to 'false' when using component.
          
              implicitWidth: 300
              implicitHeight: 300
          
              Rectangle {
                  anchors.fill: parent
                  color: "white"
          
                  // ScrollView to enable vertical scrolling for the page.
                  ScrollView {
                      id: scrollView
                      anchors.fill: parent
          
                      contentWidth: -1 // Disable horizontal scrolling
                      contentHeight: columnLayout.height
          
                      ColumnLayout {
                          id: columnLayout
          
                          anchors.fill: parent
                          clip: true
          
                          // Title text for the page.
                          Text {
                              id: titleText
                              horizontalAlignment: Text.AlignLeft
                              verticalAlignment: Text.AlignVCenter
                              color: "black"
                          }
                      }
                  }
              }
          }
          

          This works for now. But, I still don't understand why the normal one does not work. Does this have to do with something in version 6.7.3?

          1 Reply Last reply
          0
          • S Saviz has marked this topic as solved on 11 Jan 2025, 06:44
          • M Offline
            M Offline
            Markkyboy
            wrote on 11 Jan 2025, 21:02 last edited by
            #4

            It may well be something to do with the latest offering of QT, many changes have been made since 5.15.

            I looks like you have solved your problem, what was it?

            Don't just sit there standing around, pick up a shovel and sweep up!

            I live by the sea, not in it.

            1 Reply Last reply
            0

            4/4

            11 Jan 2025, 21:02

            • Login

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