Signals for entered / exited events in TabView
I have TabView
, which is 3 Tab
s, for Say tab1
, tab2
, tab3
. Each one Tab
has some widgets. I want to have some sort of signaling mechanism, so when I go into tab3
I want to set the state of some widgets (like << 27>) within tab3
, and when I leave it I want to reset their state.
Any pointers on how to achieve this? When I read the Qt 5.3 documentation about TabView
and Tab
, I didn't find any signals that were detected by them.
The alarm can be within tab3
or between TabView
and tab3
. I'm fine with any of them.
source to share
Use onVisibleChanged
Try this:
TabView {
Tab {
onVisibleChanged: console.log("hello1 "+visible)
title: "Red"
Rectangle { color: "red" }
}
Tab {
onVisibleChanged: console.log("hello2 "+visible)
title: "Blue"
Rectangle { color: "blue" }
}
Tab {
onVisibleChanged: console.log("hello3 "+visible)
title: "Green"
Rectangle { color: "green" }
}
}
source to share
Changing tabs on the Vacation tab (from false
to true
) and the input tab (from true
to false
) changes the visibility of the TWO tabs. These events are not always serialized. I had to add:
onVisibleChanged: {
if (!this.activeFocus){
// ...
}
}
But if you don't actually click on the tab, but activate it by setting the tab active
to true
, the above solution is not enough. You should use TabView.currentIndex
to compare it to static, i.e. a declarative tab index. If called for a new active tab onVisibleChanged
, then the indices must be equal.
Here's an example:
function refreshButtons(tabIndexStatic){
if (tabStepsView.currentIndex !== tabIndexStatic)
return;
buttonPrev.visible = tabIndexStatic !== 0
buttonNext.visible = tabIndexStatic !== tabStepsView.count - 1
buttonConvert.visible = tabIndexStatic === tabStepsView.count - 1
}
Tab {
title: qsTr("Tab 0")
onVisibleChanged: parent.refreshButtons(0)
// ...
}
Tab {
title: qsTr("Tab 1")
onVisibleChanged: parent.refreshButtons(1);
// ...
}
Tab {
title: "Tab 2"
onVisibleChanged: tabStepsView.refreshButtons(2)
// ...
}
}
source to share