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. swipeView setcurrentindex(1) not work
QtWS25 Last Chance

swipeView setcurrentindex(1) not work

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 3 Posters 1.2k 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1

    heme my simple code:

    import QtQuick 2.3
    import QtQuick.Controls 2.3
    import QtQuick.Controls.Material 2.3
    import QtDataVisualization 1.3
    import QtQuick.LocalStorage 2.0
    import QtQuick.Window 2.10
    import QtSensors 5.9
    import Qt.labs.calendar 1.0
    import QtGraphicalEffects 1.0
    import QtQuick.Controls.Imagine 2.3
    import QtQuick.Extras 1.4
    import QtQuick.XmlListModel 2.0
    import QtQml.Models 2.1
    import QtQuick.Layouts 1.1
    import "custom"
    import QtCharts 2.2
    
    
    ApplicationWindow {
        id: mainWindow
        visible: true
        width: 1440
        height: 900
        maximumWidth: 1440
        minimumWidth: 1440
        maximumHeight: 900
        minimumHeight: 900
    
    /* some page style setting code*/
    
        SwipeView {
            id: swipeView
            anchors.fill: parent
            currentIndex: tabBarMain.currentIndex
            visible: true
            width: 1440
            height: 900
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.preferredWidth: 1440
            Layout.preferredHeight: 900
            Layout.minimumWidth: 1440
            Layout.minimumHeight: 900
    
    
            //Loader { id: pageLoader }
    
            Connections {
                target: bcPg1.menuSetSignal
                onPressed: {
                    tabBarMain.setCurrentIndex(1)
                    swipeView.setCurrentIndex(1)
                    tabBarMain.update()
                    swipeView.update()
                    console.log(tabBarMain.currentIndex)
                }
            }
    

    console and tab is setting in the correct way at every menuSetSignal button onPressed .... but swipe non show the new content.

    Way these?
    peraphs swipeView and tabbar work ok.

    any suggest

    bkt

    J.HilkJ 1 Reply Last reply
    0
    • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

      Hi @gfxx , just one thing which i noticed, i think you might have made a mistake while copy pasting it,you need to close Connections { } before BcPG1.

      I have not completely copy pasted your code, but have replaced BcPG with an Item, and its working fine for me.

      Here is the sample code:-

       SwipeView {
          id: view
      
          currentIndex: 0
          anchors.fill: parent
          topPadding: 100
      
          Connections {
              target: firstPage.firstButton
      
              onClicked: {
                  console.log(view.currentIndex)
                  view.setCurrentIndex(2)
              }
          }
      
          Item {
              id: firstPage
      
              property alias firstButton: firstButton
      
      
              Rectangle {
                  anchors.fill: parent
                  color: "red"
              }
      
              Button {
                  id: firstButton
                  height: 100
                  width: 100
              }
      
          }
          Item {
              id: secondPage
              Rectangle {
                  anchors.fill: parent
                  color: "green"
              }
          }
          Item {
              id: thirdPage
              Rectangle {
                  anchors.fill: parent
                  color: "yellow"
              }
          }
      }
      

      For your code, is the control atleast going inside onPressed signal?
      Is your application output showing some warnings or errors?

      gfxxG Offline
      gfxxG Offline
      gfxx
      wrote on last edited by gfxx
      #8

      @Shrinidhi-Upadhyaya

      Yes for shure a copy and paste error .... but actually i try in these manner:

      • convert mybutton into a component (because I have a components that make a similar things and it works) ...
      • mycomponent.mybutton.onClicked: tabMytab.currentIndex = 1 NOT WORK AT ALL
      • mycomponent.mybutton.onClicked: tabMytab.currentIndex = 1; WORK PERFECTLY
      • Connections { ... } way not try if work now ... but I think Shrinidhi Upadhyaya is in right ... but I suspect that ";" would have served in any case

      note the ";" ..... :( ...... I'm on ubuntu 18.04, QT5.12 .....

      Thanks at All

      bkt

      J.HilkJ 1 Reply Last reply
      0
      • gfxxG gfxx

        heme my simple code:

        import QtQuick 2.3
        import QtQuick.Controls 2.3
        import QtQuick.Controls.Material 2.3
        import QtDataVisualization 1.3
        import QtQuick.LocalStorage 2.0
        import QtQuick.Window 2.10
        import QtSensors 5.9
        import Qt.labs.calendar 1.0
        import QtGraphicalEffects 1.0
        import QtQuick.Controls.Imagine 2.3
        import QtQuick.Extras 1.4
        import QtQuick.XmlListModel 2.0
        import QtQml.Models 2.1
        import QtQuick.Layouts 1.1
        import "custom"
        import QtCharts 2.2
        
        
        ApplicationWindow {
            id: mainWindow
            visible: true
            width: 1440
            height: 900
            maximumWidth: 1440
            minimumWidth: 1440
            maximumHeight: 900
            minimumHeight: 900
        
        /* some page style setting code*/
        
            SwipeView {
                id: swipeView
                anchors.fill: parent
                currentIndex: tabBarMain.currentIndex
                visible: true
                width: 1440
                height: 900
                Layout.fillWidth: true
                Layout.fillHeight: true
                Layout.preferredWidth: 1440
                Layout.preferredHeight: 900
                Layout.minimumWidth: 1440
                Layout.minimumHeight: 900
        
        
                //Loader { id: pageLoader }
        
                Connections {
                    target: bcPg1.menuSetSignal
                    onPressed: {
                        tabBarMain.setCurrentIndex(1)
                        swipeView.setCurrentIndex(1)
                        tabBarMain.update()
                        swipeView.update()
                        console.log(tabBarMain.currentIndex)
                    }
                }
        

        console and tab is setting in the correct way at every menuSetSignal button onPressed .... but swipe non show the new content.

        Way these?
        peraphs swipeView and tabbar work ok.

        any suggest

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @gfxx you need to provide some more information.

        In the example you posted your swipe view has no content components -> you can't set the index to anything but 0


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • Shrinidhi UpadhyayaS Offline
          Shrinidhi UpadhyayaS Offline
          Shrinidhi Upadhyaya
          wrote on last edited by
          #3

          Hi @gfxx , can you be bit more clear on what do you want to achieve onPressed?

          This is what i get from the question you have posted.I guess you are changing the index of the SwipeView,but thats not reflecting back!!(Is this your problem),you have already assigned currentIndex: tabBarMain.currentIndex in SwipeView, but still onPressed you are changing the currentIndex value of both TabBar and SwipeView,no need to do that.

          Shrinidhi Upadhyaya.
          Upvote the answer(s) that helped you to solve the issue.

          gfxxG 1 Reply Last reply
          0
          • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

            Hi @gfxx , can you be bit more clear on what do you want to achieve onPressed?

            This is what i get from the question you have posted.I guess you are changing the index of the SwipeView,but thats not reflecting back!!(Is this your problem),you have already assigned currentIndex: tabBarMain.currentIndex in SwipeView, but still onPressed you are changing the currentIndex value of both TabBar and SwipeView,no need to do that.

            gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by gfxx
            #4

            @all

            import QtQuick 2.3
            import QtQuick.Controls 2.3
            import QtQuick.Controls.Material 2.3
            import QtDataVisualization 1.3
            import QtQuick.LocalStorage 2.0
            import QtQuick.Window 2.10
            import QtSensors 5.9
            import Qt.labs.calendar 1.0
            import QtGraphicalEffects 1.0
            import QtQuick.Controls.Imagine 2.3
            import QtQuick.Extras 1.4
            import QtQuick.XmlListModel 2.0
            import QtQml.Models 2.1
            import QtQuick.Layouts 1.1
            import "custom"
            import QtCharts 2.2
            
            
            ApplicationWindow {
                id: mainWindow
                visible: true
                width: 1440
                height: 900
                maximumWidth: 1440
                minimumWidth: 1440
                maximumHeight: 900
                minimumHeight: 900
            
                  /* some page style setting code*/
            
                SwipeView {
                    id: swipeView
                    anchors.fill: parent
                    currentIndex: tabBarMain.currentIndex
                    visible: true
                    width: 1440
                    height: 900
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.preferredWidth: 1440
                    Layout.preferredHeight: 900
                    Layout.minimumWidth: 1440
                    Layout.minimumHeight: 900
            
            
                    //Loader { id: pageLoader }
            
                    Connections {
                        target: bcPg1.menuSetSignal
                        onPressed: {
                            tabBarMain.setCurrentIndex(1)
                            swipeView.setCurrentIndex(1)
                            tabBarMain.update()
                            swipeView.update()
                            console.log(tabBarMain.currentIndex)
                        }
                    
            
            BcPG1 {
                 id: bcPg1 /*  these is the ui.qml page  that contanis the button with id: menuSetSignal */
            }
            BcPG2 {
                 id: bcPg2
            }
            BcPG3 {
                 id: bcPg3
            }
            BcPG4 {
                 id: bcPg4
            }
            BcPG5 {
                 id: bcPg5
            }BcPG6 {
                 id: bcPg6
            }
            
            }
            
            TabBar { /* tab bar code here */ }
            
            } /* applicationwindows end */
            
            

            i hope is more clear now ...

                    Connections {
                        target: bcPg1.menuSetSignal
                        onPressed: {
                            tabBarMain.setCurrentIndex(1)
                            swipeView.setCurrentIndex(1)
                            tabBarMain.update()
                            swipeView.update()
                            console.log(tabBarMain.currentIndex)
                        }
            

            these pieces of code in my mind needs to change swipe content view on button.onPressed .... but not work at all .... only change index of tab and swipe, whitout change content page view .....

            bkt

            1 Reply Last reply
            0
            • Shrinidhi UpadhyayaS Offline
              Shrinidhi UpadhyayaS Offline
              Shrinidhi Upadhyaya
              wrote on last edited by
              #5

              Hi @gfxx ,i dont see much of a problem except few mistakes , which dont impact on your functionality,but have you aliased the menuSetSignal(button) in bcPg1?

              For example like this:-

              property alias menuSetSignal: button
              

              Shrinidhi Upadhyaya.
              Upvote the answer(s) that helped you to solve the issue.

              gfxxG 1 Reply Last reply
              0
              • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                Hi @gfxx ,i dont see much of a problem except few mistakes , which dont impact on your functionality,but have you aliased the menuSetSignal(button) in bcPg1?

                For example like this:-

                property alias menuSetSignal: button
                
                gfxxG Offline
                gfxxG Offline
                gfxx
                wrote on last edited by gfxx
                #6

                @Shrinidhi-Upadhyaya

                these my aliased row in bcPg1.ui.qml

                property alias menuSetSignal: menuSetSignal  //(the id of button)
                

                but as I see, insert a console.log row as debug ... the index of tab and swipe change .... but the page not swipe ..... swipe only if I use touch swipe on screen or tabBar press ..... if I use button.onPress .... only index change but not the page ....

                bkt

                1 Reply Last reply
                0
                • Shrinidhi UpadhyayaS Offline
                  Shrinidhi UpadhyayaS Offline
                  Shrinidhi Upadhyaya
                  wrote on last edited by
                  #7

                  Hi @gfxx , just one thing which i noticed, i think you might have made a mistake while copy pasting it,you need to close Connections { } before BcPG1.

                  I have not completely copy pasted your code, but have replaced BcPG with an Item, and its working fine for me.

                  Here is the sample code:-

                   SwipeView {
                      id: view
                  
                      currentIndex: 0
                      anchors.fill: parent
                      topPadding: 100
                  
                      Connections {
                          target: firstPage.firstButton
                  
                          onClicked: {
                              console.log(view.currentIndex)
                              view.setCurrentIndex(2)
                          }
                      }
                  
                      Item {
                          id: firstPage
                  
                          property alias firstButton: firstButton
                  
                  
                          Rectangle {
                              anchors.fill: parent
                              color: "red"
                          }
                  
                          Button {
                              id: firstButton
                              height: 100
                              width: 100
                          }
                  
                      }
                      Item {
                          id: secondPage
                          Rectangle {
                              anchors.fill: parent
                              color: "green"
                          }
                      }
                      Item {
                          id: thirdPage
                          Rectangle {
                              anchors.fill: parent
                              color: "yellow"
                          }
                      }
                  }
                  

                  For your code, is the control atleast going inside onPressed signal?
                  Is your application output showing some warnings or errors?

                  Shrinidhi Upadhyaya.
                  Upvote the answer(s) that helped you to solve the issue.

                  gfxxG 1 Reply Last reply
                  1
                  • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                    Hi @gfxx , just one thing which i noticed, i think you might have made a mistake while copy pasting it,you need to close Connections { } before BcPG1.

                    I have not completely copy pasted your code, but have replaced BcPG with an Item, and its working fine for me.

                    Here is the sample code:-

                     SwipeView {
                        id: view
                    
                        currentIndex: 0
                        anchors.fill: parent
                        topPadding: 100
                    
                        Connections {
                            target: firstPage.firstButton
                    
                            onClicked: {
                                console.log(view.currentIndex)
                                view.setCurrentIndex(2)
                            }
                        }
                    
                        Item {
                            id: firstPage
                    
                            property alias firstButton: firstButton
                    
                    
                            Rectangle {
                                anchors.fill: parent
                                color: "red"
                            }
                    
                            Button {
                                id: firstButton
                                height: 100
                                width: 100
                            }
                    
                        }
                        Item {
                            id: secondPage
                            Rectangle {
                                anchors.fill: parent
                                color: "green"
                            }
                        }
                        Item {
                            id: thirdPage
                            Rectangle {
                                anchors.fill: parent
                                color: "yellow"
                            }
                        }
                    }
                    

                    For your code, is the control atleast going inside onPressed signal?
                    Is your application output showing some warnings or errors?

                    gfxxG Offline
                    gfxxG Offline
                    gfxx
                    wrote on last edited by gfxx
                    #8

                    @Shrinidhi-Upadhyaya

                    Yes for shure a copy and paste error .... but actually i try in these manner:

                    • convert mybutton into a component (because I have a components that make a similar things and it works) ...
                    • mycomponent.mybutton.onClicked: tabMytab.currentIndex = 1 NOT WORK AT ALL
                    • mycomponent.mybutton.onClicked: tabMytab.currentIndex = 1; WORK PERFECTLY
                    • Connections { ... } way not try if work now ... but I think Shrinidhi Upadhyaya is in right ... but I suspect that ";" would have served in any case

                    note the ";" ..... :( ...... I'm on ubuntu 18.04, QT5.12 .....

                    Thanks at All

                    bkt

                    J.HilkJ 1 Reply Last reply
                    0
                    • gfxxG gfxx

                      @Shrinidhi-Upadhyaya

                      Yes for shure a copy and paste error .... but actually i try in these manner:

                      • convert mybutton into a component (because I have a components that make a similar things and it works) ...
                      • mycomponent.mybutton.onClicked: tabMytab.currentIndex = 1 NOT WORK AT ALL
                      • mycomponent.mybutton.onClicked: tabMytab.currentIndex = 1; WORK PERFECTLY
                      • Connections { ... } way not try if work now ... but I think Shrinidhi Upadhyaya is in right ... but I suspect that ";" would have served in any case

                      note the ";" ..... :( ...... I'm on ubuntu 18.04, QT5.12 .....

                      Thanks at All

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by J.Hilk
                      #9

                      @gfxx
                      great that it works for you now, but a ; at the end of line shouldn't/mustn't make a difference in qml

                      can you check, if that also makes a difference for you in the example @Shrinidhi-Upadhyaya posted?


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      gfxxG 1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk

                        @gfxx
                        great that it works for you now, but a ; at the end of line shouldn't/mustn't make a difference in qml

                        can you check, if that also makes a difference for you in the example @Shrinidhi-Upadhyaya posted?

                        gfxxG Offline
                        gfxxG Offline
                        gfxx
                        wrote on last edited by
                        #10

                        @J.Hilk for sure ... (not sure is a correct way to test, because my problem is originally become from bcPg1.menuAdminOutput, when menuAdminOutput is part of bcPg1 .... now menuAdminOutput is part of component bAdmMenu1 .... so ... any how seems parser of qt creator problem).

                        for fist try these

                        Connections {
                                        target: bcPg1.bAdmMenu1.menuAdminOutput
                                        onClicked: {
                                             tabBarMain.currentIndex = 5
                                        }
                                    }
                        

                        NOT WORK

                        for second these

                        Connections {
                                        target: bcPg1.bAdmMenu1.menuAdminOutput
                                        onClicked: {
                                             tabBarMain.currentIndex = 5;
                                        }
                                    }
                        

                        THESE WORK

                        for third these one again

                        Connections {
                                        target: bcPg1.bAdmMenu1.menuAdminOutput
                                        onClicked: {
                                             tabBarMain.currentIndex = 5
                                        }
                                    }
                        

                        And now IT WORKS .....

                        What is changed from first and third exaple??

                        bkt

                        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