[PyQt] QDockwidget advice needed

Hans-Peter Jansen hpj at urpla.net
Wed Aug 18 22:34:11 BST 2010


On Wednesday 18 August 2010, 22:10:19 danny wrote:
> FWIW, I do have Mark Summerfield's book and I agree it is brilliant.
>
> However, he does not give an example of how to connect a dock window to a
> tree item. His examples include how to keep two widgets synchronized, but
> that is not my problem. The problem with the tree and dock window, is
> that the *object* changes in the dock window and that is not covered.

Not exactly, but who cares. AFAICS, all you need is the Signals and Slots 
chapter. Unfortunately, it misses the new style signals (because Phil 
invented them later), but you should get hold of them from the beginning. 
Much less to type, better type checking, _and_ no silly Qt types anymore. 
IIRC, the later variants of Marks examples available on his site do use 
them already.

> Every time I click on a different tree node, do I need to dynamically
> connect the slots to synchronize and delete the old slot bindings? 

No, Qt and therefore PyQt is pretty clever to tidy up the mess you're 
leaving behind (e.g. objects, that going out of scope). But as long as you 
don't create widgets dynamically, you shouldn't care anyway.

> Is it 
> better stylistically to map at the item level in the tree, or at the
> aggregate tree level? In other words do I hook up slots to the leaves of
> the tree or the tree itself?

Again, No. You look for a signal that your tree view emits, when you change 
the current item. In the signal handler, you emit a custom signal, and your 
dock widget connect to that signal. Hence, every time your tree item 
changes, you should receive your custom signal (with whatever parameter) in 
the dock.

This should be doable in a few dozen lines of code..

Pete


More information about the PyQt mailing list