How can I create a properly sizing QWebView?
- by chacham15
I want to make a QWebView appear expanding to the width and height so that ideally it will have no scroll bars. Some websites may have fixed widths that wont allow this, but I am not concerned with those. In any case, I cannot do as I wish because QWebView implements sizeHint as follows:
QSize QWebView::sizeHint() const
{
return QSize(800, 600); // ####...
}
This is incorrect on a number of levels. 1. It doesnt at all take into account the size of the actual web page. 2. It doesnt take into account that the height and width are related to each other. (To prove #2 think about text in web pages that wraps to the next line.)
As a simple fix I tried to do (where QResizingWebView extends QWebView):
QSize QResizingWebView::sizeHint() const{
return this-page()-mainFrame()-contentsSize();
}
While this is closer to the result, it also has 2 flaws. 1. It doesnt take into account the relation between the displayed width/height. 2. this->page()->mainFrame()->contentsSize() is inaccurate from what I can tell from my preliminary testing (it has returned heights larger than it should under many cases, although this may be related to #1).
Does anyone have any tips to fix this?