[Qt-interest] Change layout in subclass of standard widget ?
Andreas Pakulat
apaku at gmx.de
Tue May 26 18:44:55 CEST 2009
On 26.05.09 15:58:30, Stephen Collyer wrote:
> 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 ?
No its not documented because the Qt widgets are usually not designed for
this. The widgets in most cases assume they're the "smallest sensible
implementation" for a given metaphor, so they assume they're only combined
into larger widgets and their internal structure is - internal.
> > 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".
Well, "something extra" may be not exactly the right words. The point is,
those buttons are not part of the "Table" metaphor, a table naturally
consists of a number of cells and two headers. so in this way your widget
is not a table anymore, its something that has a table and some buttons.
Andreas
--
You're almost as happy as you think you are.
More information about the Qt-interest-old
mailing list