Originally Posted by
wysota
I already told you, I even gave you a working example (post #90) which you silently ignored and another one earlier (#85) which you didn't comment as well.
I didn't intend to ignore you post.
For the post#90, I replied with the code which you asked for.
Also post #85 I have included.
Below is the current code and have also attached the screen of what I trying to do.
//ContextMenu.qml
import QtQuick 2.0
Rectangle {
id : cxtMenu
width: 140
height: 24
radius: width*0.5
color: "#222222"
Image {
id: triangle
height: 15
width: 15
anchors.top: parent.top
anchors.topMargin: 24
anchors.horizontalCenter: parent.horizontalCenter
smooth: true
source: "qrc:/images/triangle.png"
visible: true
}
Rectangle {
id:hglt
height: 24
width: 60
radius: width*0.1
anchors.top : parent.top
anchors.left: parent.left
border.color: "#000000"
border.width: 0
color: "#222222"
Text {
id:hglttext
text: qsTr("Highlight")
font.pointSize: 11
font.family: "san-serif"
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 5
smooth: true
color: "#CFCFCF"
MouseArea {
anchors.fill: parent
onClicked: {
browserwindow.cxtMenu()
}
}
}
}
Rectangle {
id:verticalline
height: parent.height
width: 1
anchors.top :parent.top
anchors.left: parent.left
anchors.leftMargin: 70
color: "#CFCFCF"
}
Rectangle {
id:annot
height: 24
width: 80
radius: width*0.1
anchors.top : parent.top
anchors.left: parent.left
anchors.leftMargin: 71
border.color: "#000000"
border.width: 0
color: "#222222"
Text {
id:annottext
text: qsTr("Annotation")
font.pointSize: 11
font.family: "san-serif"
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 5
smooth: true
color: "#CFCFCF"
MouseArea {
anchors.fill: parent
onClicked: {
browserwindow.newnotes()
}
}
}
}
}
//BrowserWindow.qml
import QtQuick 2.0
import QtQuick.Controls 1.3
import QtWebEngine 1.0
Rectangle {
id:flick
height: parent.height
width: parent.width - 5
property variant mypoint: Qt.point(10,10)
property variant pressPoint: Qt.point(10,10)
property variant releasePoint: Qt.point(10,10)
property string pagecontents: ""
property string url: ""
WebEngineView {
id: currentWebview
objectName: "webView"
//url: "http://www.google.co.in"
anchors.fill: parent
readonly property string htmlContent: content
onHtmlContentChanged: loadHtml(htmlContent, baseUrl);
MouseArea {
id : mousearea
anchors.fill: parent
onPressed: {
pressPoint.x = mouseX
pressPoint.y = mouseY
console.log("PressPoint : "+pressPoint)
}
onReleased: {
releasePoint.x = mouseX
releasePoint.y = mouseY
console.log("releasePoint : "+releasePoint)
if(pressPoint != releasePoint )
{
mouse.accepted = false
currentWebview.runJavaScript("window.getSelection()", function(result) { console.log("selected Text =" + result.toString());} )
cntxtMenu.visible = true
cntxtMenu.x = mouseX - 80
cntxtMenu.y = mouseY - 38
}
}
}
}
}
//ContextMenu.qml
import QtQuick 2.0
Rectangle {
id : cxtMenu
width: 140
height: 24
radius: width*0.5
color: "#222222"
Image {
id: triangle
height: 15
width: 15
anchors.top: parent.top
anchors.topMargin: 24
anchors.horizontalCenter: parent.horizontalCenter
smooth: true
source: "qrc:/images/triangle.png"
visible: true
}
Rectangle {
id:hglt
height: 24
width: 60
radius: width*0.1
anchors.top : parent.top
anchors.left: parent.left
border.color: "#000000"
border.width: 0
color: "#222222"
Text {
id:hglttext
text: qsTr("Highlight")
font.pointSize: 11
font.family: "san-serif"
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 5
smooth: true
color: "#CFCFCF"
MouseArea {
anchors.fill: parent
onClicked: {
browserwindow.cxtMenu()
}
}
}
}
Rectangle {
id:verticalline
height: parent.height
width: 1
anchors.top :parent.top
anchors.left: parent.left
anchors.leftMargin: 70
color: "#CFCFCF"
}
Rectangle {
id:annot
height: 24
width: 80
radius: width*0.1
anchors.top : parent.top
anchors.left: parent.left
anchors.leftMargin: 71
border.color: "#000000"
border.width: 0
color: "#222222"
Text {
id:annottext
text: qsTr("Annotation")
font.pointSize: 11
font.family: "san-serif"
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 5
smooth: true
color: "#CFCFCF"
MouseArea {
anchors.fill: parent
onClicked: {
browserwindow.newnotes()
}
}
}
}
}
//BrowserWindow.qml
import QtQuick 2.0
import QtQuick.Controls 1.3
import QtWebEngine 1.0
Rectangle {
id:flick
height: parent.height
width: parent.width - 5
property variant mypoint: Qt.point(10,10)
property variant pressPoint: Qt.point(10,10)
property variant releasePoint: Qt.point(10,10)
property string pagecontents: ""
property string url: ""
WebEngineView {
id: currentWebview
objectName: "webView"
//url: "http://www.google.co.in"
anchors.fill: parent
readonly property string htmlContent: content
onHtmlContentChanged: loadHtml(htmlContent, baseUrl);
MouseArea {
id : mousearea
anchors.fill: parent
onPressed: {
pressPoint.x = mouseX
pressPoint.y = mouseY
console.log("PressPoint : "+pressPoint)
}
onReleased: {
releasePoint.x = mouseX
releasePoint.y = mouseY
console.log("releasePoint : "+releasePoint)
if(pressPoint != releasePoint )
{
mouse.accepted = false
currentWebview.runJavaScript("window.getSelection()", function(result) { console.log("selected Text =" + result.toString());} )
cntxtMenu.visible = true
cntxtMenu.x = mouseX - 80
cntxtMenu.y = mouseY - 38
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Screen Shot 2015-07-09 at 11.45.18 AM.jpg
What I am trying to do is. on mouse release will bring in a context menu to highlight the selected text or add annotation to selected text
Originally Posted by
wysota
Don't do anything. It works by default. However I think you want something else -- you want a mouse area over an item and still have items reach the webview. For that, as said many times already, events need to be ignored (accepted = false) in the mouse area. Nobody will do that for you -- you have to decide yourself which events to consume in the mouse area and which to pass to the underlying item
Yes, without including the mousearea selection was available. After including the mousearea only selection is unavailable.
I am confused to choose which event needs to be ignored to make the text selection available.
Originally Posted by
wysota
Wow... we are going to reach 100 posts in this thread...
Thx Wysota and anda_skoa for your continuous guidance and help. Without you both, I wouldn't have been able to reach where I am now. Thanks a ton.
Hope, I would be able to complete what I am trying with your help.
Bookmarks