[Qt-interest] setLayout for QMainWindow

Steven Woody narkewoody at gmail.com
Tue Jan 20 09:57:14 CET 2009


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.
>
> Andreas
>

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?



More information about the Qt-interest-old mailing list