Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. how to get the real width and hight of the web pages what have loaded?

how to get the real width and hight of the web pages what have loaded?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 1 Posters 211 Views
  • 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.
  • N Offline
    N Offline
    nicker player
    wrote on 26 Aug 2024, 02:58 last edited by
    #1
    //m_WidgetBrowser means the widget of the webengineview
    connect(m_WidgetBrowser->page(), &QWebEnginePage::loadFinished, [this](bool ok) {
                if (ok) {
                    m_WidgetBrowser->page()->runJavaScript("document.body.scrollWidth", [this](const QVariant &widthResult) {
                        int pageWidth = widthResult.toInt();
                        int viewWidth = m_WidgetBrowser->width();
                        double zoomFactorWidth = static_cast<double>(viewWidth) / static_cast<double>(pageWidth);
                        m_WidgetBrowser->page()->runJavaScript("document.body.scrollHeight;", [this,pageWidth](const QVariant &heightResult) {
                            int pageHeight = heightResult.toInt();
                            int viewHeight = this->m_WidgetBrowser->height();
                            emit onSignalResize(pageWidth,pageHeight);
                            //the signal is to reszie the widget of the webegine m_WidgetBrowser->resize(pageWidth,pageHeight);
    
                        });
                    });
                }
            });
        }
    

    I tested the code above.but on some platforms it worked.some dosent.
    Is there any way to get the real width and height of the pages which loadfinished?

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nicker player
      wrote on 27 Aug 2024, 03:59 last edited by
      #2

      and if I set the source file whit the setHtml() function.
      it is hard to get the real height and width if the source was made by the txt.

      1 Reply Last reply
      0

      2/2

      27 Aug 2024, 03:59

      • Login

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