[PyQt] Embedding QWidgets within a parent
Phil Thompson
phil at riverbankcomputing.com
Fri Apr 25 16:36:40 BST 2014
On 25/04/2014 1:23 pm, Chris Wood wrote:
> Hmm, I've been through that tutorial several times, and I thought I
> was getting the hang of stuff, but that tutorial doesn't seem to
> mention anywhere anything about how to set parents or children.
> However, it seems it might be easier than I thought it was - I hadn't
> realised that I could do something like:
>
> class webwidget(QtGui.QWidget):
>
> def __init__(self):
> super(webwidget, self).__init__()
>
> self.b = Browser()
> self.b.load(QUrl('http://www.google.com [7]'))
>
> self.grid = QtGui.QGridLayout()
> self.grid.addWidget(self.b,0,1)
>
> self.setLayout(self.grid)
>
> class Browser(QWebView):
>
> def __init__(self):
> QWebView.__init__(self)
> self.loadFinished.connect(self._result_available)
>
> def _result_available(self, ok):
> frame = self.page().mainFrame()
>
> and that Google now does appear in my gui! :) (n.b. is there a better
> way to do it - should I call load() somewhere else?) but, how does the
> comment about children / parents relate to this?
If that is all you are doing then why bother? QWebView is a widget
itself.
Phil
More information about the PyQt
mailing list