Hi!

i have a class which implement a simple collapsible widget:

Qt Code:
  1. class CollapsibleWidget: public QGroupBox
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. CollapsibleWidget( const QString& t, QWidget* p = 0 );
  7.  
  8. void setCollapsibleLayout(QLayout* l);
  9.  
  10. protected:
  11. QBoxLayout *mainLayout;
  12. QWidget *mainWidget;
  13.  
  14. protected slots:
  15. void collapse(bool on);
  16. };
To copy to clipboard, switch view to plain text mode 

and here the implementation:

Qt Code:
  1. CollapsibleWidget::CollapsibleWidget (const QString& t, QWidget* p):
  2. {
  3. setCheckable(true);
  4.  
  5. mainWidget=new QWidget();
  6.  
  7. mainLayout=new QVBoxLayout(this);
  8. mainLayout->addWidget(mainWidget);
  9.  
  10. connect(this, SIGNAL(toggled(bool)), this, SLOT(collapse(bool)));
  11. }
  12.  
  13.  
  14. void CollapsibleWidget::setCollapsibleLayout (QLayout* l)
  15. {
  16. mainWidget->setLayout(l);
  17. }
  18.  
  19.  
  20. void CollapsibleWidget::collapse (bool on)
  21. {
  22. mainWidget->setVisible(on);
  23. }
To copy to clipboard, switch view to plain text mode 

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):

Qt Code:
  1. LogWidget::LogWidget(const QString& t, const Symulator *s, const QStringList &levels, QWidget* p):
  2. CollapsibleWidget(t, p), symulator(s), maxLevel(0)
  3. {
  4. id=logWidgetCounter++;
  5. name=t;
  6.  
  7. level=new QComboBox();
  8.  
  9. if (levels.size()<2)
  10. level->setVisible(false);
  11.  
  12. foreach(QString str, levels)
  13. {
  14. level->addItem(str);
  15. }
  16.  
  17. QStringList header;
  18. header << "komunikat" << "chwila czasu";
  19.  
  20. model=new QStandardItemModel(this);
  21. model->setHorizontalHeaderLabels(header);
  22.  
  23. view=new QTreeView();
  24. view->setItemsExpandable(false);
  25. view->setRootIsDecorated(false);
  26. view->setHeaderHidden(false);
  27. view->setModel(model);
  28.  
  29. l->addWidget(view);
  30. l->addWidget(level);
  31.  
  32. setCollapsibleLayout(l);
  33.  
  34.  
  35. connect(view, SIGNAL(clicked(QModelIndex)), this, SLOT(selected(QModelIndex)));
  36. connect(symulator, SIGNAL(resetSimulation()), this, SLOT(reset()));
  37. connect(level, SIGNAL(currentIndexChanged(int)), this, SLOT(levelIndexChanged(int)));
  38. }
To copy to clipboard, switch view to plain text mode 


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?