Qt Code:
WebEngineView { id: currentWebview objectName: "webView" 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 [B] mouse.accepted = true[/B] } onReleased: { releasePoint.x = mouseX releasePoint.y = mouseY if(pressPoint != releasePoint ) { cntxtMenu.x = releasePoint.x - 74 cntxtMenu.y = releasePoint.y - 30 cntxtMenu.visible = true [B]mouse.accepted = true[/B] currentWebview.runJavaScript("window.getSelection()", function(result) { console.log("selected Text =" + result.toString());} ) } } } }To copy to clipboard, switch view to plain text mode
I have included as accepted = true, still I dont get the selection
Added after 45 minutes:
I have included the mouse.pressed = true in mousePressed as well, still selection not available
Last edited by ejoshva; 9th July 2015 at 11:52.
to pass on to webview, it should be true as per the docs.
I will have to define by own logic, when I set it to false.
I kept mouse.accepted = false for both mousepressed and mousereleased, then the selection is available.
Now how to get the text selection meaning on which event? since the control doesn't reach mousearea.
once selection is done, I will have to bring up the context menu.
Which event should be captured??
on WebView or mousearea, I should look to capture the drag event.
the text is selected on the page loaded on webview, (i.e.) it's child rite. May be I am wrong in this.
Last edited by ejoshva; 9th July 2015 at 13:10.
Which docs?
As expected
What "control" doesn't reach mouse area?
Mouse Release ends the selection, no?
So you get the release first, you set up a delayed trigger, you let the event pass to the web view, you get the selection in the delayed trigger.
No, drag is something entirely different.
Cheers,
_
mouseevent#accepted
I have capture the mousePressed point and trying to compare that with the mouseRelease point to bring up the context menu.
But I am not able to capture the mousePressed Point in the mousePressed event defined in the MouseArea.
I have already included ContextMenu.visible = true in OnReleased.
But it doesn't show up when the accepted is false.
When the accepted is false, whatever I write in mouseArea events like onpressed, onreleased doesn't get executed.
In that case, where do I have to capture them. Please bare with me for asking this again.
What is a delayed trigger ?
Yes I get it.
Let me quote these docs and highlight the relevant part: Setting accepted to true prevents the mouse event from being propagated to items below this item.
What for? Does the decision of showing a context menu depend on the distance between press and release?I have capture the mousePressed point and trying to compare that with the mouseRelease point to bring up the context menu.
Why not? I think my example code demonstrates how to do that.But I am not able to capture the mousePressed Point in the mousePressed event defined in the MouseArea.
What do you mean? Does the code execute but does nothing or does the code not execute at all? I would expect that onReleased of the overlay MouseArea might not execute if you cleared the accepted flag on the press event because of what I said a couple of posts earlier. Did you verify that?I have already included ContextMenu.visible = true in OnReleased.
But it doesn't show up when the accepted is false.
Did you run my example from post #90? Can you modify my example to demonstrate that?When the accepted is false, whatever I write in mouseArea events like onpressed, onreleased doesn't get executed.
Yes, if the pressed point and released point are not same, I will show the context menu at the released point.
Even from your example, I get only the mousePressed event.
I control doesnt reach the mouseReleased event itself. Only in mouseReleased, I am setting it to visible.
[/QUOTE] yes, QMLWebEngineTest.zip
Have attached the whole project making use of the QML code you gave.
Here the control reaches the mousePressed event alone. It doesn't reach the mouseReleased event.
What I am doing is, if the mouse pressed point and mouse released point are not same, and if the selected text is not empty, will show the context menu.
And if they are the same?
The point is that you do get it.Even from your example, I get only the mousePressed event.
If it is not the same item which accepted mousePressEvent, it will not get mouseReleaseEvent.I control doesnt reach the mouseReleased event itself. Only in mouseReleased, I am setting it to visible.
Last time you said it didn't reach mousePressedHere the control reaches the mousePressed event alone. It doesn't reach the mouseReleased event.
Why can't you do that from the HTML page like I suggested some number of posts earlier? It is much easier to get the presses there and then transmit that information to QtQuick so that it can show a context menu.What I am doing is, if the mouse pressed point and mouse released point are not same, and if the selected text is not empty, will show the context menu.
not gonna do anything with it unless, it's a link.
yes I get it
didn't get you. here mousearea is the item which accepted mousePressEvent and same mousearea only accepting mouseReleaseEvent.
I am getting confused
Is it that when I say mouse.accepted = false in onPressed event, I wont get the control in onReleased event??
my bad, I had given the print after the accepted = false.
The code is already there, as I have said many posts back, I am porting from QGraphicsWebView to WebEngineView.
There are some thousand html pages already created.To change all the html pages, its difficult . May be for future ones can include.
I have to make use of existing code of the app alone and can't make changes to existing html pages
Last edited by ejoshva; 10th July 2015 at 12:13.
so you mean to say that, after setting the mouse.accepted = false in onPressed event, I cant have some code executed in onReleased event ??
even if I am executing javacript, when will I capture it? on the webengineview to bring up the contextmenu qml.
can you please help to bring up in this flow only rather than bringing up a new one.
Last edited by ejoshva; 11th July 2015 at 07:15.
It seems so. I think you could install an event filter on the element instead and intercept those events before they reach the webview without using a mouse area but that's much more complicated than what you are currently doing.
The web component needs to have a mechanism (such as QWebChannel I mentioned earlier) that lets you communicate with Qt Quick. When you detect a press, a release and do your logic, simply tell Qt Quick to open the context menu.even if I am executing javacript, when will I capture it? on the webengineview to bring up the contextmenu qml.
I don't understand what you mean.can you please help to bring up in this flow only rather than bringing up a new one.
Bookmarks