I want to display HTML in a label like container in a GraphicsView. I can't use QGraphicsTextItem because I need it to inherit from QGraphicsLayoutItem. So, I am attempting to setup a QGraphicsWebView where I can set the preferred width of the view (or page) and allow the height of the view to be determined based on the contents of the page. Thus far unsuccessful. I would have thought you could set

webview->page()->setPreferredContentsSize(QSize(300, -1));

However this yields and invalid size and the page ends up returning the default size and then does not adhere to my width requirement.

I've since provided an actual size for the PreferredContentsSize, subclassed QGraphicsWebView and am trying too provide the desired sizeHint. However I haven't been able to find the actual height of the page given the width. I've thoroughly reviewed various methods on the QGraphicsWebView, QWebFrame and QWebPage and have sifted through some of the QWebCore code as well.

Is there a clear way to achieve this goal?

Thanks much.