How to properly size QWebView?
-
Yes, don't. Having a browser that randomly changes size as you move from page to page is a user interface disaster.
The height of a web page is driven by the width of the available display space. The contentsSize() height is based on rendering HTML with the constraint of the widget's current width. Changing the widget width after the calculation necessarily invalidates the previously calculated height.
-
The thing is that what is being rendered is not the internet, but rather emails which are formatted using html (therefore, there is no navigation). Also the reason that I want to resize the email whenever the size of the window changes.
-
eh. What?
You want to fix window size to size of webpage? Why?You can write something like:
@
//...
QWebView *view;
QMainWindow *window = new QMainWindow();
window->setCentralWidget(view);
window->show();
@Or use some layout:
@
//...
QWidget window = new QWidget();
QLayout layout = new QLayout();
QWebView* view = new QWebView();layout->addWidget(view);
window->setLayout(layout);
window->show();
@This will keep your WebView expanding
-
peppy, I want to render an email in the smallest height possible for a given width (the width of the window) so that scroll bars are avoided. The first example does not attempt to limit the height of the widget, and the second does not work because it relies on sizeHint being accurate, which it isnt.
-
The smallest height as possible? The smallest height as possible depends on that current website, how is done, isn't it?
-
yes, the smallest height possible does depend on the html, hence the problem
-
The solution I ended up going with is implementing heightForWidth (see the new question)
-
And what will you app do, if my site is higher than screen of some user?
-
QResizingWebView will be contained by a QScrollArea
-
So you go out of your way to avoid the scroll bars that are naturally provided by QWebView when they are needed, only to wrap the whole thing in a QScrollArea so that you get scroll bars when you need them. Colour me confused.
-
I know this has been a while, but essentially what I wanted to do here was to mix htmlviews and widgets into one scrolling view. Therefore, each element inside the scrolling view has to always be at its full size. Does that make sense?