problem with Inheritance and QTreeView
Hi!
i have a class which implement a simple collapsible widget:
Code:
{
Q_OBJECT
public:
CollapsibleWidget
( const QString
& t,
QWidget* p
= 0 );
void setCollapsibleLayout
(QLayout* l
);
protected:
protected slots:
void collapse(bool on);
};
and here the implementation:
Code:
CollapsibleWidget
::CollapsibleWidget (const QString
& t,
QWidget* p
):{
setCheckable(true);
mainLayout->addWidget(mainWidget);
connect(this, SIGNAL(toggled(bool)), this, SLOT(collapse(bool)));
}
void CollapsibleWidget
::setCollapsibleLayout (QLayout* l
) {
mainWidget->setLayout(l);
}
void CollapsibleWidget::collapse (bool on)
{
mainWidget->setVisible(on);
}
the idea is simple: it's a groupbox with checkbox, if user press the chechbox, the mainWidget is being hidden.
now i create a LogWidget class which inherits from CollapsibleWidget. It's used to display logs
(this class is quite big so i'll only show constructor):
Code:
LogWidget
::LogWidget(const QString
& t,
const Symulator
*s,
const QStringList &levels,
QWidget* p
):CollapsibleWidget(t, p), symulator(s), maxLevel(0)
{
id=logWidgetCounter++;
name=t;
if (levels.size()<2)
level->setVisible(false);
{
level->addItem(str);
}
header << "komunikat" << "chwila czasu";
model->setHorizontalHeaderLabels(header);
view->setItemsExpandable(false);
view->setRootIsDecorated(false);
view->setHeaderHidden(false);
view->setModel(model);
l->addWidget(view);
l->addWidget(level);
setCollapsibleLayout(l);
connect(symulator, SIGNAL(resetSimulation()), this, SLOT(reset()));
connect(level, SIGNAL(currentIndexChanged(int)), this, SLOT(levelIndexChanged(int)));
}
and now the problem:
i use QTreeView + QStandardItemModel to display log's data. that's working
but as You can see i setup header ( model->setHorizontalHeaderLabels(header); )
Imho it should display the header over log's data, but it doesn't.
The header appears after i add first line to log. but it's doesn't contain data i wanted, the column names are set to "1", "2", ....
When i use model->setHorizontalHeaderLabels(header) again after i add some data to log, it's being displayed correctly.
the weirdest thing is that, if i create QTreeView + QStandardItemModel (same code as in LogWidget constructor) in some other widget (which inherits directly from QWidget) the QTreeView contains correct header.
any suggestions?