[Qt-interest] Change layout in subclass of standard widget ?
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Tue May 26 20:32:07 CEST 2009
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Stephen Collyer
Sent: Tuesday, May 26, 2009 7:59 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Change layout in subclass of standard widget ?
2009/5/26 Andreas Pakulat <apaku at gmx.de>
On 26.05.09 10:52:37, Stephen Collyer wrote:
>
> This doesn't seem entirely correct to me. All classes derived from QWidget
> support setLayout() so it would seem possible, at least in principle,
> to change the layout of a standard widget. The QWidget docs give an
> example of this being done:
>
> http://doc.qtsoftware.com/4.5/qwidget.html#setLayout
>
> I suspect I'm merely doing it incorrectly.
No, what you're missing is that a QTableView doesn't actually have an
internal layout. It is completely drawing its scrollarea itself. So if you
start to set layouts on this widget, you're breaking tons of assumptions
done when the QTableView code was written.
OK. This is a good point. However, how does one know in advance if
any given widget uses an internal layout ? Is this documented ?
IMHO you're wrong here, because your widget is not a tableview anymore. Its
a tableview+something extra. So in fact the proper relation of your widget
to the tableview should be a has-A relation, not is-A.
I would have to disagree. If we followed your argument, then no derived
class could contain any additional members, since then it would be a "class
+ something extra".
Anyway, it looks like I'll have to go for composition, given that QTableView
has no layout. That seems like a pity.
--
Stephen Collyer
---------------
It can be quite confusing... especially when you're coming up to speed in QT...
But in reality, except for layout specific widgets (such QMainWindow and QScrollArea), I cant think any QT Widgets where you can "relayout" the internals.
QT is designed, to use composition for layout, but to use derivation for functionality.
Even QMainWindow, you create a "widget" lay it out the way you want, and put it into the mainwindow.
Scott
More information about the Qt-interest-old
mailing list