[PyQt] Embedding QWidgets within a parent

Florian Bruhin me at the-compiler.org
Thu Apr 24 20:16:50 BST 2014


* Chris Wood <c.c.wood at gmail.com> [2014-04-24 19:29:47 +0100]:
> If I have a standalone widget, what's the best way to integrate (/embed) it
> within a QMainWindow / parent QWidget? I know that a QScrollArea has a
> setWidget method - but is there a better / lower level / more abstract way
> of achieving it?
> 
> (In my particular case, I'm using QtWebKit; using this answer (
> http://stackoverflow.com/a/13386109/889604) as a starting point, I'd like
> to embed 'view' (which is an instance of Browser) into a parent QWidget.
> I'd like to think that because QWebView inherits QWidget, this should be
> easy(!))

The answer almost seems too simple... but you're aware of the
parent-argument of QObjects (and thus also QWidgets)?

Basically, if you don't give a parent (wv = QWebView()), it's a
standalone/toplevel widget, and if you do (wv = QWebView(mainwindow)),
it's inside that widget.

You might really want to take a look at a basic PyQt tutorial though,
if that really was the problem. I can recommend [1] - even when you
want to use PyQt5, the examples are trivial to port (just import some
things from QtWidgets instead of QtGui usually)

[1] http://zetcode.com/gui/pyqt4/

-- 
() ascii ribbon campaign - stop html mail    www.asciiribbon.org
/\ www.the-compiler.org  | I love long mails http://email.is-not-s.ms/
Joe Cool always spends the first two weeks at college sailing his frisbee. -- 
Snoopy 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140424/da6f4194/attachment.sig>


More information about the PyQt mailing list