How can I disable selection property on Qwebview
-
wrote on 13 Oct 2010, 23:48 last edited by
I have QWebview which has text image icon and some other things on my touch screen.
When I press finger and drag every thing gets selected which is not Desired.So I started trying some workaround and I just accepted QMouseEvent in mouseMoveEvent() function which prevents selection but again other functionality which needs this also gets prevented.
Is there any way I can simply stop this Selection property on Text and other image icons on WVebView.
I saw this "http://doc.qt.nokia.com/qt-maemo-4.6/maemo5-webview.html":http://doc.qt.nokia.com/qt-maemo-4.6/maemo5-webview.html but this is not the ideal case for me as I have Map on screen and user wont be able to pan that.Any help will be appreciated.
Prakash[edit: fixed link / chetankjain]
-
wrote on 14 Oct 2010, 00:01 last edited by
I had the same problem some days ago. I couldn't find a nice way to fix it on the QWebPage side, so I fixed it on the html side.
Try to set the CSS property:
@-webkit-user-select:none;@ -
wrote on 14 Oct 2010, 00:29 last edited by
We don't yet have a convenient API for interaction with touch screen. You will have to do some of the work yourself to avoid selection while having a nice touch interface.
I suggest you to look at "http://gitorious.org/yberbrowser":http://gitorious.org/yberbrowser and
"http://gitorious.org/light":http://gitorious.org/light which are handling touch input quite nicely. -
wrote on 19 Oct 2010, 03:14 last edited by
Hi All, This does not seems to fix the problem, as I want to disable the selection only on QWebView text and graphics, I have other control like map where I need to have mouse clicked and drag enable so looks like I need to make some changes in the qwebkit, can any one please give me some hint what should I looking for?
-
wrote on 19 Oct 2010, 08:26 last edited by
[quote author="mprakash" date="1287458087"]Hi All, This does not seems to fix the problem, as I want to disable the selection only on QWebView text and graphics, I have other control like map where I need to have mouse clicked and drag enable so looks like I need to make some changes in the qwebkit, can any one please give me some hint what should I looking for?[/quote]
In that case, you will have to wait a little I am afraid. There is a bug report open to add such a feature, but no patch has been posted yet: "https://bugs.webkit.org/show_bug.cgi?id=38520":https://bugs.webkit.org/show_bug.cgi?id=38520
Feel free to post a patch if you want to help.
-
wrote on 19 Oct 2010, 17:10 last edited by
I want to do it, I need some help if some body can guide me or give me some hint, I how I can do this in webkit or Qt code.
-
wrote on 19 Oct 2010, 17:36 last edited by
You could look at how -webkit-user-select is implemented. Disabling selection is probably using the same path.
-
wrote on 20 Oct 2010, 09:57 last edited by
There is a thread on this subject on the mailing list: "https://lists.webkit.org/pipermail/webkit-qt/2010-October/000896.html":https://lists.webkit.org/pipermail/webkit-qt/2010-October/000896.html
-
wrote on 21 Dec 2010, 06:44 last edited by
I bug is already filed here at bugzilla, for this
https://bugs.webkit.org/show_bug.cgi?id=38520 -
wrote on 23 Dec 2010, 03:45 last edited by
Wow here is way you can do it
@
QApplication a(argc, argv);
QWebView *view = new QWebView;
view->load(QUrl("http://google.com"));
view->page()->settings()->setUserStyleSheetUrl(QUrl::fromLocalFile("mycss.css"));
view->show();
return a.exec();@your css file should be like this:
body {
-webkit-user-select: none;
} -
wrote on 23 Dec 2010, 03:48 last edited by
You know what, I just tried putting the css thing in resource file and now I can see it is part of my binary so no need of css file. function setUserStyleSheetUrl() is dong the job of disabling selection.
-
wrote on 23 Dec 2010, 07:29 last edited by
This works great, after long time I got something. Thanx immii
-
wrote on 30 Jan 2013, 09:29 last edited by
your submitted code is very helpful for disable the selection on text and image.
but your code is not helpful in case while user drag the image with press button. -
wrote on 22 Oct 2015, 10:04 last edited by
bool QWebView::findText ( const QString & subString, QWebPage::FindFlags options = 0 )
To clear the selection, just pass an empty string. -
your submitted code is very helpful for disable the selection on text and image.
but your code is not helpful in case while user drag the image with press button.wrote on 20 Nov 2015, 06:34 last edited by@kmsharad83 This is what I do in jQuery. You can adapt it to your needs:
$(document).ready(function(){ // Prevent anchor links and buttons and .nodrag items from being dragged $('A,BUTTON,.nodrag,IMG') .css('-moz-user-select','none') .css('-webkit-user-select','none') .bind('selectstart', function(e) { e.preventDefault(); return false; }) .bind('draggesture', function(e) { e.preventDefault(); return false; }) .bind('draggable', function(e) { e.preventDefault(); return false; }) .bind('dragstart', function(e) { e.preventDefault(); return false; }); });