qtqmlqtquick2tabviewqt5.3

Signals for entered/exited events in TabView


I have a TabView, which has 3 Tabs, Say tab1, tab2, tab3. Each Tab has some widgets. I want to have some kind of signalling mechanism, so that when I enter tab3, I want to set the state of some of the widgets (e.g. a TextField) within tab3 and when I leave it, I want to reset their state.

Any pointers on how to achieve this? When I read Qt 5.3 documentation about TabView and Tab, I did not find any signals exposed by them.

Signalling can be within tab3 or between Tabview and tab3. I am fine with either of these.


Solution

  • 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" }
        }
    }