PDA

View Full Version : Performance with QTableView and QAbstractTableModel



MBex
24th February 2009, 16:08
Hello,

At the moment i am developing an apllication for displaying database contents by QTableView and QAbstractTableModel.
For this purpose i wrote a test application to check the performance. I set only 200 rows and 37 columns but the whole applications slows a bit down. Additionaly the selection of cells is relatively slow.
Is there any way to increase the performance of this test application?

Test.h

class Model: public QAbstractTableModel
{
Q_OBJECT
public:
Model();
virtual int rowCount( const QModelIndex &parent) const;
virtual int columnCount(const QModelIndex &parent) const;
virtual QVariant data( const QModelIndex &index, int role) const;
QVariant headerData(
int section,
Qt::Orientation orientation,
int role) const;
};

class Window: public QMainWindow
{
Q_OBJECT
public:
Window(QWidget *aParent = 0);
private:
QTableView m_view;
Model m_model;
};


Test.cpp

Model::Model()
{
}

//
//-----------------------------------------------------------------------------
int Model::rowCount(const QModelIndex &parent) const
{
return 200;
}

//
//-----------------------------------------------------------------------------
int Model::columnCount(const QModelIndex &parent) const
{
return 37;
}

//
//-----------------------------------------------------------------------------
QVariant Model::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
{
return QVariant(QString("%1, %2 esfgsdgsdgsdgsdg")
.arg(index.row())
.arg(index.column()));
}
return QVariant();
}

//
//-----------------------------------------------------------------------------
QVariant Model::headerData(
int section,
Qt::Orientation orientation,
int role) const
{
if (section < 37)
return QVariant(QString("Spalte: %1").arg(section));
else
return QVariant();
}

//
//-----------------------------------------------------------------------------
Window::Window(QWidget *aParent):
QMainWindow(aParent),
m_view(this)
{
setCentralWidget(&m_view);
m_view.setModel(&m_model);
m_view.verticalHeader()->setDefaultSectionSize(17);
}

I hope someone can help me.
Thanks in advance.

regards Marco B.

caduel
24th February 2009, 17:12
setUniformRowHeights(true) on the view will speed things up.

side note: you should check role in headerData(), too.

talk2amulya
24th February 2009, 17:17
doesnt that work only for QTreeView?

MBex
25th February 2009, 08:04
I read from the Qt Assistant that setUniformRowHeights(true) is only available on QTreeViews.
Looks like there is no way of speeding up my application :(.