0
votes

I have a screen containing frame (as one qml file) - the content of it is stored as separate widgets in separate files. Currently it looks like:

//screen qml
MyScreen
{
  ...
  //other stuff

  Widget1
  {
    visible: isWidget1Active
    ...
  }

  Widget2
  {
    visible: isWidget2Active
    ...
  }
}

//widget1 qml
Widget1
{
  //label  
  //button
}

//widget2 qml
Widget2
{
  //label
  //button1
  //button2
  //button3
}

The widgets will cover the same area (but they have different content) and I want to show only one of them in the same time. Of course I can change the visibility by checking which widget should be currenlty active but I'm not sure it's the correct approach. I want to have support for much more than two widgets. In this case the screen qml will be much bigger and will have much more conditions.

Is possible to switch the widget qml instead of setting the visibility for each widget?

2

2 Answers

0
votes

You can use StackView, if you want have feature full navigation between your widgets. Another approach is to use ListView or another view Item which will show a single delegate each time.

0
votes

I did it by using loader and sending string with the path to the qml from c++ file.

But I have one problem - I need to trigger function inside the switched widget from the screen. The instance of the Widget class is not visible in MyScreen so I'm not able to use the connect.

I can reload the qml by emitting change on the string containing path to the source but I have to perform it two times - with empty string and the correct one (which has been set earlier) - otherwise the qml will be not reloaded. It's not the best solution because in this case I only have "access" to the constructor - it will be called after qml reloading. I can use this approach but maybe is possible to do it in better way.