Prevent RMB on top of WebView



  • I have a Rectangle (z:999) on top of a WebView (z:1) inside a Flickable (z:2) and if I use accepted:true inside the onClicked handler then it prevents LMB and MMB events from falling through to the WebView item but not RMB events, they still cause the context menu to pop up and activate JS click events on the WebView page underneath.

    How can I prevent RMB events falling through to a WebView item?

    @import QtQuick 1.0
    import QtWebKit 1.0

    Rectangle {
    id: rootWindow
    width: 960; height: 540
    color: "#3f3f3f"

    Flickable {
    z: 2
    anchors.fill: parent
    contentHeight: webView.height
    contentWidth: webView.width

    WebView {
      id: webView
      z: 1; url: "http://google.com"
      preferredWidth: rootWindow.width
      preferredHeight: rootWindow.height
    }
    

    }

    Rectangle {
    id: webMenu
    z: 998; y: -144
    width: parent.width; height: 144
    color: "#2f2f2f"
    Text {
    text: "<h1>Web Menu goes here"
    anchors.centerIn: parent
    }
    }

    Rectangle {
    id: topEdge
    z: 999; width: parent.width; height: 8
    color: "red"; opacity: 0.01; visible: true
    anchors.top: parent.top
    state: "TOPEDGE_CLOSED"

    MouseArea {
      anchors.fill: parent
      hoverEnabled: true
      //acceptedButtons: Qt.RightButton
      acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
      onEntered: parent.opacity = 1
      onExited: parent.opacity = 0.01
      onClicked: {
        accepted: true
        topEdge.state = (topEdge.state == "TOPEDGE_CLOSED")
        ? "TOPEDGE_OPEN" : "TOPEDGE_CLOSED"
    

    console.log("topEdge clicked="+mouse.button+" ("+mouse.x+","+mouse.y+")")
    }
    }

    states:[
      State { name: "TOPEDGE_OPEN"
        PropertyChanges { target: webMenu; y: 0; opacity: 0.9 }
      },
      State { name: "TOPEDGE_CLOSED"
        PropertyChanges { target: webMenu; y: -144; opacity: 0 }
      }
    ]
    
    transitions: [
      Transition { to: "*"
        NumberAnimation { target: webMenu
          properties: "opacity"; duration: 150
          easing.type: Easing.InOutCubic
        }
      }
    ]
    

    }
    }
    @



  • FWIW I posted a bug report here...

    http://bugreports.qt.nokia.com/browse/QTCOMPONENTS-399


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.