How to filter out «back» events in a web view?
-
wrote on 2 Dec 2013, 03:17 last edited by
Hello, all!
I develop a form based upon QWebView (and have QWebView and QWebPage inherited for additional work). It's important that a user can press Backspace without returning to whatever page it was opened before. How do I do this in QtWebKit?
-
wrote on 16 Dec 2013, 20:48 last edited by
Try:
@bool CWebView:eventFilter( QObject pObj, QEvent event )
{
QKeyEvent pkeyEvent = (QKeyEvent)event;if (Qt::ControlModifier == pKeyEvent->state())
{
switch (pKeyEvent->key())
{
case Qt::Key_Backspace:
//something
break;
default:
return false;
break;
}
}
return true;
}@ -
wrote on 16 Dec 2013, 22:30 last edited by
Make sure you clear the history when there's a page change.
-
wrote on 16 Dec 2013, 22:53 last edited by
clear history:
@#include <QWebHistory>
...
QWebView* CWebView;
...
CWebView->history()->clear();@Or use Javascrip-t
http://stackoverflow.com/a/8969975/1518921 -
wrote on 2 Jan 2014, 15:30 last edited by
Guilherme, unfortunately, it appers there is no "right" way to only what I want and leave the application intact (see the answer to my "issue":https://bugreports.qt-project.org/browse/QTBUG-35555). I might call it zeroth solution.
The first solution works only when a user is not supposed to use Backspace, the second one requires to log visited pages for navigation to work.
We have chosen the third solution, which is to make the application single-paged.
Anyways, thank you for your suggestions.
[quote author="Guilherme Nascimento" date="1387234402"]clear history:
@#include <QWebHistory>
...
QWebView* CWebView;
...
CWebView->history()->clear();@Or use Javascrip-t
http://stackoverflow.com/a/8969975/1518921[/quote] -
wrote on 3 Jan 2014, 20:01 last edited by
and the third in javascrip-t? Try: http://stackoverflow.com/questions/20343115/how-to-filter-out-back-events-in-a-qt-web-view/20814671#20814671