PDA

View Full Version : QWebView and Qt::Key_Menu problem



oficjalne100
10th October 2011, 16:19
Hi

I have QWebView object and I use customContextMenuRequested() signal connected to my slot createPopupForOutput(). Obviously I have 2 cases when my menu must appear: 1) after right mouse button (RMB) click and 2) after key Qt::Key_Menu press. RMB works as I expect, but Qt::Key_Menu works wrong (no menu appears). I debugged my app and discovered that in both cases my slot createPopupForOutput() is called properly (so this is no my event handing fault). I think that the only difference is that parameter to createPopupForOutput(const QPoint& aPoint) is (0, 0) when I press Qt::Key_Menu and aPoint has other values when I click RMB (for example (178, 46)). So my question is:

How to raise custom popup menu on QWebView by pressing Qt::Key_Menu?

thanks

wysota
10th October 2011, 16:29
The real question is where do you want to show it.

oficjalne100
10th October 2011, 18:30
I want show it near selection or url. Because this behaviour is natural and well known from webbrowsers.

wysota
10th October 2011, 18:35
So if the point you get is invalid, find the selection, get its geometry and show the menu there.

oficjalne100
11th October 2011, 12:36
How am I supposed to find geometry of selection or geometry of url?

Now I use
QWebHitTestResult lHit = mOutput->page()->mainFrame()->hitTestContent(aPoint);
and when aPoint == (0,0)
lHit.isContentSelected() == false
!lHit.linkUrl().isEmpty() == false

I have no idea how to handle special case when aPoint == (0,0) and some selection exist or some url link has focus.

I looked in Browser demo from qt/demos/ directory. They made another approach - they subclass QWebView and redefine
contextMenuEvent(QContextMenuEvent *event)
It works but a bit weird: When some url has focus then after pressing menu key, menu appear in the upper left corner of the screen (not page corner, not window corner, but screen corner). Menu for selected text appear almost near selection but in my opinion that position is also invalid (distanse between selected text and menu is too big). And more! Menu for selected text is invalid - it has item "reload" instead "copy" (after RMB click it has "copy" - as supposed).

I also searched web for "qt qwebview selection geometry" but find nothing apropriate.

wysota
11th October 2011, 12:50
How am I supposed to find geometry of selection or geometry of url?
No idea, most likely through QWebPage API.