Search code examples
qtqmlstackview

Stackview calling slots for previous screen


I am implementing stackview in my application.

SwipeView {
id: swipeView
anchors.fill: parent
currentIndex: showfooter.currentIndex

        DashboardListView{
        id:dashboard
        }

        Settings{
        id:setting
        }

        Cart{
        id:cart
        }
}


StackView {
   id: stackView

   initialItem: Pane {
      id: pane
   }
}

When i am loading some other screen(like SightDescription.qml) from DashboardListView using push method and cliking somewhere on that screen its calling slots for DashboardListView. DashboardListView Screen controls are getting onclick signal. Is there any setting related to stack view that I need to do, I read stackview's documentation but did not find anything to restrict this behavior.


Solution

  • It seems like the Pane is usually intercepting the mouse events, so the lower Items cannot receive them.

    When you push the new item on the StackView the Pane becomes visible: false and therefore does not care for input anymore. If the new Item does not handle the mouse events, they will propagate to the lower Item.

    To prevent that, you have various options:

    1. Make sure that all Items pushed on the StackView will handle mouse events, e.g. by making a Pane or a MouseArea the root item.
    2. Place a MouseArea directly below the StackView that is only enabled when there are Items on the StackView
    3. Some more... e.g. installing EventFilters in C++ e.t.c. but I think 1 and 2 should be suffice and be easy to implement.