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. Prevent RMB on top of WebView
QtWS25 Last Chance

Prevent RMB on top of WebView

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.8k Views
  • 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.
  • M Offline
    M Offline
    mc0nstable
    wrote on last edited by
    #1

    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
        }
      }
    ]
    

    }
    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mc0nstable
      wrote on last edited by
      #2

      FWIW I posted a bug report here...

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

      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