PDA

View Full Version : Avoid changing qml tab until condition is met



ifhmcos
4th April 2018, 18:41
I have a tab system using http://doc.qt.io/qt-5/qtquick-customitems-tabwidget-tabwidget-qml.html, in which one tab is a configuration tab, once the user has modified something I want to warn them if they try to change tabs, gving them the option to exit without applying changes. Is there a proper way to do this without changing the tabWidget code?

My idea is to add a boolean property to the tabWidget and the proper tab to set it when something has been modified and then on onClicked check if it is set to not change the tab. Is this the proper way?

something like


property bool canChangeIndex: false
// ... tabWidget code
// on the onClicked signal

onClicked: if (canChangeIndex) tabWidget.current = index