PDA

View Full Version : QTabWidget + QTreeView



Jonny174
18th April 2011, 14:47
I have one QTabWidget and class inherits of QTreeView:


class TreeView : public QTreeView
{
Q_OBJECT

QVector<EventsRecord> m_pRecord;

public:
TreeView( QWidget *parent = 0 );
virtual ~TreeView();
void clearRecords() { m_pRecord.resize(0); };
void push_backRec( EventsRecord &er ) { m_pRecord.push_back( er ); };
QVector<EventsRecord> getRecords() { return m_pRecord; };
};


In vector m_pRecord puts info about files. On main window I add tab on QTabWidget:


void MainWindow::addTab()
{
m_pTreeView = new TreeView( m_pTab );
m_pTreeView->setObjectName( QString("m_pProp%1").arg( m_pTab->count() ) );
m_pTreeView->clearRecords();
int TAB = m_pTab->addTab( m_pTreeView, tr(" ") );
m_pTab->setTabToolTip( m_pTab->count() - 1, QString("%1").arg( m_pTab->count() - 1 ) );
}

m_pTab - pointer to QTabWidget. After this I set model:


TreeView *m_pProps = fr->findChild<TreeView *>( QString("m_pProp%1")
.arg( m_pTab->tabToolTip( m_pTab->currentIndex() ).toInt() ) );

SmallListModel *pSmallModel = new SmallListModel( m_pProps->getRecords(), m_pProps );
m_pProps->setModel( pSmallModel );

Why didn't work? I want add many tabs conteints TreeView with one model and different content.
constructor SmallListModel:


SmallListModel::SmallListModel( QVector<EventsRecord> &records, QObject *parent ):
QAbstractListModel( parent ),
m_pRecords( &records )
{
}