Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QGraphicsWebView rendering webpage issue



  • Hi Guys,

    I tried to render webpage using QGraphicsWebView here.

    Page is rendering but some how text is not rendered correctly. Am using QT 5, is it problem in QT 5 becoz above is perfectly rendering using QT 4.7 or am i missing any thing that hampers text rendering in webpage.

    Below the handling code

    @ scene = new QGraphicsScene(ui->graphicsView);

    ui->graphicsView->setScene(scene);
    ui->graphicsView->setAttribute(Qt::WA_OpaquePaintEvent);
    
    webView = new  QGraphicsWebView;
    webView->setPalette(QApplication::palette("QWebView"));
    webView->page()->setPalette(QApplication::palette("QWebPage"));
    
    scene->addItem(webView);
    
    glWid = new QGLWidget();
    
    ui->graphicsView->setViewport(glWid);
    ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    
    ui->graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
    
    
    QWebSettings *settings = QWebSettings::globalSettings();
    settings->setAttribute(QWebSettings::JavascriptEnabled, true);
    
    mainpage = new WebPage(this);
    webView->setPage(mainpage);
    
    webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOn);
    webView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
    
    webView->resize(1024, 768);
    
    webView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    
    webView->page()->settings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled,true);
    webView->page()->settings()->setAttribute(QWebSettings::AutoLoadImages,true);
    webView->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
    webView->page()->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows,true);
    
    webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
    webView->page()->setForwardUnsupportedContent(true);
    
    webView->setUrl(QUrl(QStringLiteral("http://www.google.co.in")));@
    

    Yugan.



  • Able to solve the problem.

    Removed following code in above. It rendered perfectly.
    @ glWid = new QGLWidget();

    ui->graphicsView->setViewport(glWid);
    ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    
    ui->graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);@
    

    Hope it help someone.....!!

    Yugan



  • Hi Yugan,

    Thank you very much for the help. Such a nice example and it really worked for me.

    Thank you,

    Tushar Kachhadiya



  • @tushar Note that you may want to use QOpenGLWidget these days instead of QGLWidget


Log in to reply