[Qt-interest] setLayout for QMainWindow
Andreas Pakulat
apaku at gmx.de
Tue Jan 20 10:56:33 CET 2009
On 20.01.09 16:57:14, Steven Woody wrote:
> On Tue, Jan 20, 2009 at 4:38 PM, Andreas Pakulat <apaku at gmx.de> wrote:
> > On 20.01.09 15:52:57, Steven Woody wrote:
> >> On Tue, Jan 20, 2009 at 3:12 PM, J-P Nurmi <jpnurmi at gmail.com> wrote:
> >> > On Tue, Jan 20, 2009 at 5:21 AM, Steven Woody <narkewoody at gmail.com> wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >> Does it make any sense if I call setLayout() member for a QMainWindow?
> >> >
> >> > You're on the right track. QMainWindow has its own private layout to handle
> >> > toolbars, dock widgets, status bar etc. so it doesn't make sense, indeed.
> >> > The main window layout is described in QMainWindow documentation.
> >> >
> >>
> >> Thank you! And, I am thinking that if QMainWindow can override the
> >> setLayout() method and raise a exception when it is invoked, thinks
> >> will be more clear and less confusing.
> >
> > Not really, as Qt doesn't use exceptions and more importantly its
> > technically not possible (in Qt4). setLayout is non-virtual so you can't
> > override it easily and being sure your overridden method is always called.
> > All it takes is a cast to QWidget, or some function that takes a QWidget as
> > input and calls setLayout.
> >
> > Besides, nobody stops you from writing your own mainwindow layouting class
> > and use that instead of the normal layout class that QMainWindow uses.
>
> Thank you for your explanation. And, if not bothering you, since I
> am not using C++/Qt and actually using Python Qt, so I am interesting
> another question: you know, in Python any method is virtual, so even
> though the setLayout() is non-virtual in C++, I think it should be
> virtual in Python Qt, am I right?
But QMainWindow is a C++ class, so C++ rules apply. PyQt only wraps the C++
API to make it accessible in Python. What you probably could do is write
your own QMainWindow subclass in Python that overrides setLayout()
apropriately and then always use that one instead of QMainWindow directly.
This might still break if any non-Python code accesses such a mainwindow.
Andreas
--
Troubled day for virgins over 16 who are beautiful and wealthy and live
in eucalyptus trees.
More information about the Qt-interest-old
mailing list