Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Missing mouse events with StackView and OpenGL
Forum Updated to NodeBB v4.3 + New Features

Missing mouse events with StackView and OpenGL

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 748 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tom_H
    wrote on last edited by
    #1

    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
        }
        ...
    }
    
    DiracsbracketD 1 Reply Last reply
    0
    • T Tom_H

      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
          }
          ...
      }
      
      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      Hi @Tom_H
      This seems to have nothing to do with whether you are using a StackedView 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 custom QQuickItem and added the mousePressEvent() and hoverMoveEvent() 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 the initialItem of the StackView. Yet, I still get all the mouse events: clicking and hovering works?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tom_H
        wrote on last edited by
        #3

        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()
            }
        }
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved