Missing mouse events with StackView and OpenGL
-
Hello. I'm writing an OpenGL Android app using the technique shown in the openglunderqml example. In main.qml, I used an ApplicationWindow containing MyQuickItem and everything was fine until I needed to add more UI screens.
I decided to use a StackView, so I moved the block containing MyQuickItem to MainPage.qml and set the main.stackview.initialItem to MainPage.qml.
But now my C++ code doesn't receive any mouse/touch events, which I need for rotating the object.
Is there a way for me to receive mouse events using StackView? If not, is there another solution?
Thanks.
main.qml:
ApplicationWindow { StackView { id: stackview width: parent.width initialItem: "MainPage.qml" } ... }
MainPage.qml:
import MyQuickItem 1.0 Page { MyQuickItem { id: app } ... }
main.qml that works:
ApplicationWindow { MyQuickItem { id: app } ... }
-
Hi @Tom_H
This seems to have nothing to do with whether you are using aStackedView
or not.I tried with the Simple Pie Chart example from:
http://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html
as my customQQuickItem
and added themousePressEvent()
andhoverMoveEvent()
handlers to it. (Since you are targetting touch devices it seems, that last one won't be of interest to you, but I added it to test those events as well.)void mousePressEvent(QMouseEvent* event) { QQuickItem::mousePressEvent(event); qDebug() << "Pressed: " << event->pos(); } void hoverMoveEvent(QHoverEvent* event) { QQuickItem::hoverMoveEvent(event); qDebug() << "Moved: " << event->pos(); }
Then, I wrapped the whole thing exactly as you do, in its own QML file, since a
Page
, and then use it as that as theinitialItem
of theStackView
. Yet, I still get all the mouse events: clicking and hovering works? -
Thank you for investigating, but your example doesn't use OpenGL. This problem seems to be unique to this method of OpenGL and StackView. I have found two solutions, one using an invisible StackView, and the other using a Popup.
Solution 1:
ApplicationWindow { MyQuickItem { id: app } StackView { id: stack anchors.fill: parent visible: false // Setting opacity to 0 doesn't work, it still hides mouse events. } function showpage(page) { stack.visible = true stack.push(page) } function closepage() { stack.pop() stack.visible = false } }
Solution 2:
ApplicationWindow { MyQuickItem { id: app } // Define a Popup for each page Popup { id: page2 anchors.fill: parent Page2 {} } function showpage2() { page2.open() } }