Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. How can I disable selection property on Qwebview
Forum Updated to NodeBB v4.3 + New Features

How can I disable selection property on Qwebview

Scheduled Pinned Locked Moved Qt WebKit
15 Posts 7 Posters 16.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mprakash
    wrote on 13 Oct 2010, 23:48 last edited by
    #1

    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]

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danilocesar
      wrote on 14 Oct 2010, 00:01 last edited by
      #2

      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;@

      <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
      Software Engineer

      1 Reply Last reply
      0
      • B Offline
        B Offline
        benjamin.poulain
        wrote on 14 Oct 2010, 00:29 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mprakash
          wrote on 19 Oct 2010, 03:14 last edited by
          #4

          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?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            benjamin.poulain
            wrote on 19 Oct 2010, 08:26 last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mprakash
              wrote on 19 Oct 2010, 17:10 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                benjamin.poulain
                wrote on 19 Oct 2010, 17:36 last edited by
                #7

                You could look at how -webkit-user-select is implemented. Disabling selection is probably using the same path.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  benjamin.poulain
                  wrote on 20 Oct 2010, 09:57 last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    Immii
                    wrote on 21 Dec 2010, 06:44 last edited by
                    #9

                    I bug is already filed here at bugzilla, for this
                    https://bugs.webkit.org/show_bug.cgi?id=38520

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      Immii
                      wrote on 23 Dec 2010, 03:45 last edited by
                      #10

                      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;
                      }

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        Immii
                        wrote on 23 Dec 2010, 03:48 last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mprakash
                          wrote on 23 Dec 2010, 07:29 last edited by
                          #12

                          This works great, after long time I got something. Thanx immii

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            kmsharad83
                            wrote on 30 Jan 2013, 09:29 last edited by
                            #13

                            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.

                            M 1 Reply Last reply 20 Nov 2015, 06:34
                            0
                            • G Offline
                              G Offline
                              gbmm
                              wrote on 22 Oct 2015, 10:04 last edited by
                              #14

                              bool QWebView::findText ( const QString & subString, QWebPage::FindFlags options = 0 )
                              To clear the selection, just pass an empty string.

                              1 Reply Last reply
                              0
                              • K kmsharad83
                                30 Jan 2013, 09:29

                                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.

                                M Offline
                                M Offline
                                maximo
                                wrote on 20 Nov 2015, 06:34 last edited by
                                #15

                                @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;
                                    });
                                });
                                
                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved