Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWebView vs QWebPage

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)

like image 541
ChrisW Avatar asked Jun 24 '14 00:06

ChrisW


1 Answers

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?

like image 60
Trilarion Avatar answered Sep 21 '22 13:09

Trilarion