QWebView vs QWebPage
Asked Answered
P

2

6

The documentation (in PyQt at least) for QWebView says: 'The QWebView class provides a widget that is used to view and edit web documents', whereas QWebPage says: 'The QWebPage class provides an object to view and edit web documents'. Given that these effectively mean the same thing:

  • Is there a historical reason why these 2 classes evolved?
  • Is one any better to use than the other in any particular circumstance?

(This stems from the fact the I'm using a javascript library embedded within a PyQt application; I'm currently using QWebView, but only QWebPage has a method for catching javascript errors, so was considering whether it was worth translating my code to subclass QwebPage instead)

Preachy answered 24/6, 2014 at 0:12 Comment(0)
L
7

From the documentation it says

QWebPage holds a main frame responsible for web content, settings, the history of navigated links and actions. This class can be used, together with QWebFrame, to provide functionality like QWebView in a widget-less environment.

Also QWebView inherits from QWidget while QWebPage does not.

My guess is therefore that QWebView is just a widget being able to load and display HTML while QWebPage can be used with a view or without a view. Also QWebPage has more functionality like settings or history of nagivation.

Now a widget-less environment is for example QtCore.QCoreApplication.

It seems that you would use QWebPage for example when writting an application for scraping web content while you would prefer QWebView when you just want to load and display some web content somewhere in your application. QWebView being a widget will always want to display something.

Historically they were both introduced with Qt 4.4.

The open questions are how much they share internally and if there is something you cannot do or cannot emulate with QWebView that you can do with QWebPage?

Leija answered 24/6, 2014 at 9:31 Comment(0)
C
0

QWebView is a QWidget that owns a QWebPage. If you build a widget-based application, use QWebView and set your own page with QWebView::setPage(). Of course, you can pass an object of a QWebPage subclass to that function.

You can access the current page of the widget with QWebView::page().

Casey answered 16/1, 2022 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.