Jugdish
6th October 2009, 16:32
What's the best way to subclass an existing composite QWidget and make changes to its layout (for example, add an additional widget to it?)
Specifically, what I'm attempting to do is make my own subclass of QTreeView that has a page navigation widget at the bottom. I have tried this:
class MyTree : public QTreeView
{
public:
MyTree(QWidget *parent = 0);
private:
PageNavigatorWidget *pageNavigator;
}
MyTree::MyTree(QWidget *parent) : QTreeView(parent)
{
pageNavigator = new PageNavigatorWidget(this);
QVBoxLayout layout;
layout.addWidget(this);
layout.addWidget(pageNavigator);
this->setLayout(layout);
}
But this doesn't work.
The reason I'm trying to subclass QTreeView rather than just subclass QWidget and have a QTreeView as a data member is that I want my class to have all the same methods as QTreeView, so that it can be treated as one.
Specifically, what I'm attempting to do is make my own subclass of QTreeView that has a page navigation widget at the bottom. I have tried this:
class MyTree : public QTreeView
{
public:
MyTree(QWidget *parent = 0);
private:
PageNavigatorWidget *pageNavigator;
}
MyTree::MyTree(QWidget *parent) : QTreeView(parent)
{
pageNavigator = new PageNavigatorWidget(this);
QVBoxLayout layout;
layout.addWidget(this);
layout.addWidget(pageNavigator);
this->setLayout(layout);
}
But this doesn't work.
The reason I'm trying to subclass QTreeView rather than just subclass QWidget and have a QTreeView as a data member is that I want my class to have all the same methods as QTreeView, so that it can be treated as one.