[PyQt] Newbie QMainWindow tips

Eric Frederich eric.frederich at gmail.com
Thu Sep 16 18:26:10 BST 2010


On Thu, Sep 16, 2010 at 11:55 AM, fpp <fpp.gsp at gmail.com> wrote:

> On Thu, Sep 16, 2010 at 5:02 PM, Eric Frederich
> <eric.frederich at gmail.com> wrote:
> > Trying to get my first PyQt MainWindow application going.
> > Its going to be to edit multiple [we'll just call them] documents in
> tabs.
> > I will have several dockwidgets that need to correspond to the currently
> > selected tab.
> > So when the tab changes, or the data within the document changes, several
> > dockwidgets need to be kept in sync.
> > Some questions.
> > 1) How do I create static members for these dockwidgets on my subclass of
> > QMainWindow?
> > I'd like to do this so I don't have to pass around the actual reference
> to
> > an instance of the subclass (just import MyMainWindow at the top and get
> it
> > using MyMainWindow.dockWidgetX).
> > Right now I'm creating them during __init__ of my QMainWindow subclass
> and
> > they actually take references to other instance objects but I can
> re-factor
> > it to get those things later on.
> > Is having static members an advisable thing to do?  If not, please tell
> me a
> > better way to do it.  Passing around instances of the main window seems
> like
> > its wrong to me, but again, I'm a newbie.
>
> I'm not sure I understand this one correctly, but if you create your
> project with eric4 (and thus design your UI with Qt Designer), that is
> exactly the result you will get, so it's probably good practice...
>
> > 2) What is a good strategy for keeping the dock widgets in sync?
>
> The standard Qt way is to connect the signal emitted by the tab bar
> when you change tabs, to a slot (method) in your dock widgets so they
> will update their contents accordingly.
>

fpp, you didn't 'reply to all'
Since I'm replying to you I'm bringing the discussion back to the mailing
list.

In regard to question 2)
So if I connect the tab bar's currentChanged(int) signal to a dock widget's
method, where does the dock widget get the data from?
Would the dock widget instance need to have a pointer to the the tab widget
or to something else?
This is what I'm confused about.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100916/41a6e667/attachment.html>


More information about the PyQt mailing list