[Qt-interest] QAbstractItemModel::setHeaderData() and headerData()
Sean Harmer
sean.harmer at maps-technology.com
Fri Jan 29 17:16:10 CET 2010
Hi,
On Friday 29 January 2010 16:03:38 j wrote:
> > I think this is where your design error is!
> > Don't do this please. It is not supported by Qt to inherit from QObject
> > twice. Furthermore, you are confusing the different roles the
> > components play. A model is something very different from a view. If you
> > want to combine them in a single class, you should a has-a instead of an
> > is-a relation.
>
> hmm, yes, well.. I'm implementing a specific view on a specific model,
> so I felt in this case it made sense to have this is-a relation.
> But I followed your advice, and now I have a working pattern.
> Would you agree on this :
OK so why not do the simple thing and derive your own view that contains the
model? E.g.
class MyModel : public QTableModel
{
...
};
class MyView : public QTableView
{
public:
MyView( QWidget* parent = 0 )
: QTableView( parent ),
m_model( new MyModel )
{
setModel( m_model );
}
...
private:
MyModel* m_model;
};
No need for multiple inheritance. Just get you MyModel class to override the
headerData() function as normal and you are set.
Or did I miss something subtle that you need in addition?
Cheers,
Sean
More information about the Qt-interest-old
mailing list