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. Multiple, identical instances of WebView, dynamically created
Forum Updated to NodeBB v4.3 + New Features

Multiple, identical instances of WebView, dynamically created

Scheduled Pinned Locked Moved Solved Qt WebKit
multipleqwebview
5 Posts 2 Posters 3.1k 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    Hi

    I have a qWebView that is used as GUI. I created it in the Designer and additionally set some things from code. This is about it:

    ui setup for webGUI (generated by compiler after graphical setup):

    	webGUI = new QWebView(centralWidget);
    	webGUI->setObjectName(QString::fromUtf8("webGUI"));
    	webGUI->setGeometry(QRect(280, 190, 150, 120));
    	webGUI->setAcceptDrops(false);
    	webGUI->setStyleSheet(QString::fromUtf8("background-color: rgba(127, 127, 127, 0);"));
    	webGUI->setUrl(QUrl("about:blank"));
    	webGUI->setRenderHints(QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing);
    
      ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
      ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
      ui->webGUI->hide();
    

    I'm using the JavaScript Bridge to get inputs(clicks) made in the webGUI into my C++ code and act on it.

    I now need to have multiple, fully identical webViews as selectable GUI's for fast switching between GUI pages without having to always load the new webGUI from the server in a single webView.
    The multiples can be fixed, though it would be a plus to be able to add them at run-time as needed with a limit in quantity.

    What is the best way to do this? Of, course, I could add the same init code like 10 times, but that not really seems an elegant solution. Do I create a new class, or ... ?
    How about the JS Bridge, the same function should be invoked from every instance of the view.

    Thanks for some guidance.

    McLionM K 2 Replies Last reply
    0
    • McLionM McLion

      Hi

      I have a qWebView that is used as GUI. I created it in the Designer and additionally set some things from code. This is about it:

      ui setup for webGUI (generated by compiler after graphical setup):

      	webGUI = new QWebView(centralWidget);
      	webGUI->setObjectName(QString::fromUtf8("webGUI"));
      	webGUI->setGeometry(QRect(280, 190, 150, 120));
      	webGUI->setAcceptDrops(false);
      	webGUI->setStyleSheet(QString::fromUtf8("background-color: rgba(127, 127, 127, 0);"));
      	webGUI->setUrl(QUrl("about:blank"));
      	webGUI->setRenderHints(QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing);
      
        ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
        ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
        ui->webGUI->hide();
      

      I'm using the JavaScript Bridge to get inputs(clicks) made in the webGUI into my C++ code and act on it.

      I now need to have multiple, fully identical webViews as selectable GUI's for fast switching between GUI pages without having to always load the new webGUI from the server in a single webView.
      The multiples can be fixed, though it would be a plus to be able to add them at run-time as needed with a limit in quantity.

      What is the best way to do this? Of, course, I could add the same init code like 10 times, but that not really seems an elegant solution. Do I create a new class, or ... ?
      How about the JS Bridge, the same function should be invoked from every instance of the view.

      Thanks for some guidance.

      McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #2

      Anyone a good suggestion ... ?

      1 Reply Last reply
      0
      • McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        Forgot to update this .... solved.
        I added code to create GUI's as needed, dynamically.

        1 Reply Last reply
        0
        • McLionM McLion

          Hi

          I have a qWebView that is used as GUI. I created it in the Designer and additionally set some things from code. This is about it:

          ui setup for webGUI (generated by compiler after graphical setup):

          	webGUI = new QWebView(centralWidget);
          	webGUI->setObjectName(QString::fromUtf8("webGUI"));
          	webGUI->setGeometry(QRect(280, 190, 150, 120));
          	webGUI->setAcceptDrops(false);
          	webGUI->setStyleSheet(QString::fromUtf8("background-color: rgba(127, 127, 127, 0);"));
          	webGUI->setUrl(QUrl("about:blank"));
          	webGUI->setRenderHints(QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing);
          
            ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
            ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
            ui->webGUI->hide();
          

          I'm using the JavaScript Bridge to get inputs(clicks) made in the webGUI into my C++ code and act on it.

          I now need to have multiple, fully identical webViews as selectable GUI's for fast switching between GUI pages without having to always load the new webGUI from the server in a single webView.
          The multiples can be fixed, though it would be a plus to be able to add them at run-time as needed with a limit in quantity.

          What is the best way to do this? Of, course, I could add the same init code like 10 times, but that not really seems an elegant solution. Do I create a new class, or ... ?
          How about the JS Bridge, the same function should be invoked from every instance of the view.

          Thanks for some guidance.

          K Offline
          K Offline
          Konstantin Tokarev
          wrote on last edited by
          #4

          @McLion said in Multiple, identical instances of WebView, dynamically created:

          I now need to have multiple, fully identical webViews as selectable GUI's for fast switching between GUI pages without having to always load the new webGUI from the server in a single webView.

          This is wrong assumption: QtWebKit has multiple tiers of memory caches, so navigation from one page to another will not invoke any network requests in case all resources are cached. (You can also provide disk cache so it could survive application restarts, if needed) In particular look at QWebSettings::setMaximumPagesInCache() - if your UI consists of, say, 5 pages, you should set it to at least 5 to get best performance.

          If you still see that application makes unnecessary network requests because of some resources getting evicted from cache, you may want to tune sizes of other caches, in particular setObjectCacheCapacities()

          Approach with multiple views is optimal when you want all those pages to be present on screen at the same time, or have indpendent "tabs" like in a browser with separate navigation histories and possibility to do background work like playing music

          McLionM 1 Reply Last reply
          1
          • K Konstantin Tokarev

            @McLion said in Multiple, identical instances of WebView, dynamically created:

            I now need to have multiple, fully identical webViews as selectable GUI's for fast switching between GUI pages without having to always load the new webGUI from the server in a single webView.

            This is wrong assumption: QtWebKit has multiple tiers of memory caches, so navigation from one page to another will not invoke any network requests in case all resources are cached. (You can also provide disk cache so it could survive application restarts, if needed) In particular look at QWebSettings::setMaximumPagesInCache() - if your UI consists of, say, 5 pages, you should set it to at least 5 to get best performance.

            If you still see that application makes unnecessary network requests because of some resources getting evicted from cache, you may want to tune sizes of other caches, in particular setObjectCacheCapacities()

            Approach with multiple views is optimal when you want all those pages to be present on screen at the same time, or have indpendent "tabs" like in a browser with separate navigation histories and possibility to do background work like playing music

            McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by
            #5

            @Konstantin-Tokarev said in Multiple, identical instances of WebView, dynamically created:

            Approach with multiple views is optimal when you want all those pages to be present on screen at the same time, or have indpendent "tabs" like in a browser with separate navigation histories and possibility to do background work like playing music

            This is about what we do. The screen is divided into various sections that are used for various menus, sub-menus, lists ... and more. These need to be loaded and shown/hidden separately or at the same time. The GUI is completely based on webpages with html/css/php/js.

            I have it working pretty smart now, though there are some limits like a key can not be sent to a webGUI that is hidden for instance, which would be great to preload a GUI section before showing.

            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