How to filter out «back» events in a web view?
-
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?
-
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;
}@ -
Make sure you clear the history when there's a page change.
-
clear history:
@#include <QWebHistory>
...
QWebView* CWebView;
...
CWebView->history()->clear();@Or use Javascrip-t
http://stackoverflow.com/a/8969975/1518921 -
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] -
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