swipeView setcurrentindex(1) not work
-
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
-
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?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
-
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
-
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.
-
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.
@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 .....
-
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
-
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
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 ....
-
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? -
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?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
-
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
@gfxx
great that it works for you now, but a;
at the end of line shouldn't/mustn't make a difference in qmlcan you check, if that also makes a difference for you in the example @Shrinidhi-Upadhyaya posted?
-
@gfxx
great that it works for you now, but a;
at the end of line shouldn't/mustn't make a difference in qmlcan you check, if that also makes a difference for you in the example @Shrinidhi-Upadhyaya posted?
@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??