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. Get the current page of stackView?
Qt 6.11 is out! See what's new in the release blog

Get the current page of stackView?

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

    Hello, I switch the content in the stackview through the button event, so I define two components and use id as the unique identifier.
    But I want to get whether the current page is a certain page when the button is clicked, and if it is, I won’t switch it. So is the current page content obtained through view or currentItem? When obtaining future content and comparing components, should it be compared with the component id or with what to determine whether it is a certain component? (Actually, where does the following if statement compare with the current content of the stackview and the component? ID?)
    code show as below:

        Button
        {
            id: closeBtn
            x: 400
            y: 0
            width: 25
            height: 25
            text: qsTr("close")
            onClicked:
            {
                
                if(pages.currentItem == license)
                {
                    return
                }else
              {
                     pages.push(license)
                  }
            }
    
        }
    
        StackView
        {
            id: pages
            x: 0
            y: 25
            width: 500
            height: 316
    
            anchors.fill: parent
    
            initialItem: welcome
            replaceEnter: Transition
            {
                PropertyAnimation
                {
                    target: stackView
                    property: "opacity"
                    from: 0
                    to: 1
                    duration:700
                    easing.type: Easing.InOutElastic;
                    easing.amplitude: 2.0;
                    easing.period: 1.5
                }
            }
            replaceExit: Transition
            {
                PropertyAnimation
                {
                    target: stackView
                    property: "opacity"
                    from: 1
                    to: 0
                    duration:500
                    easing.type: Easing.InOutElastic;
                    easing.amplitude: 2.0;
                    easing.period: 1.5
                }
            }
    
    
            Component
            {
                id: welcome
    
                Rectangle
                {
                    width: 200
                    height: 200
                    x: 20
                    y: 50
                    color: "#00c20c"
                }
            }
    
            Component
            {
    
                id: license
                Rectangle
                {
                    width: 200
                    height: 200
                    x: 200
                    y: 50
                    color: "#FFC0CB"
                }
            }
    
    KroMignonK 1 Reply Last reply
    0
    • N Nan Feng

      Hello, I switch the content in the stackview through the button event, so I define two components and use id as the unique identifier.
      But I want to get whether the current page is a certain page when the button is clicked, and if it is, I won’t switch it. So is the current page content obtained through view or currentItem? When obtaining future content and comparing components, should it be compared with the component id or with what to determine whether it is a certain component? (Actually, where does the following if statement compare with the current content of the stackview and the component? ID?)
      code show as below:

          Button
          {
              id: closeBtn
              x: 400
              y: 0
              width: 25
              height: 25
              text: qsTr("close")
              onClicked:
              {
                  
                  if(pages.currentItem == license)
                  {
                      return
                  }else
                {
                       pages.push(license)
                    }
              }
      
          }
      
          StackView
          {
              id: pages
              x: 0
              y: 25
              width: 500
              height: 316
      
              anchors.fill: parent
      
              initialItem: welcome
              replaceEnter: Transition
              {
                  PropertyAnimation
                  {
                      target: stackView
                      property: "opacity"
                      from: 0
                      to: 1
                      duration:700
                      easing.type: Easing.InOutElastic;
                      easing.amplitude: 2.0;
                      easing.period: 1.5
                  }
              }
              replaceExit: Transition
              {
                  PropertyAnimation
                  {
                      target: stackView
                      property: "opacity"
                      from: 1
                      to: 0
                      duration:500
                      easing.type: Easing.InOutElastic;
                      easing.amplitude: 2.0;
                      easing.period: 1.5
                  }
              }
      
      
              Component
              {
                  id: welcome
      
                  Rectangle
                  {
                      width: 200
                      height: 200
                      x: 20
                      y: 50
                      color: "#00c20c"
                  }
              }
      
              Component
              {
      
                  id: license
                  Rectangle
                  {
                      width: 200
                      height: 200
                      x: 200
                      y: 50
                      color: "#FFC0CB"
                  }
              }
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @Nan-Feng said in Get the current page of stackView?:

      Hello, I switch the content in the stackview through the button event, so I define two components and use id as the unique identifier.
      But I want to get whether the current page is a certain page when the button is clicked, and if it is, I won’t switch it. So is the current page content obtained through view or currentItem? When obtaining future content and comparing components, should it be compared with the component id or with what to determine whether it is a certain component? (Actually, where does the following if statement compare with the current content of the stackview and the component? ID?)

      I think you are mixing up something.
      With Component, you are creating a new component type inside the current QML file. Like you would do it with an external QML file.
      But StackView.currentItem is an instance of a component.

      => You are trying to compare potatoes and oranges ;)

      You can do it by creating an instance of component license or by comparing component type.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      1

      • Login

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