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
{
Q_OBJECT
public:
Model();
virtual int rowCount
( const QModelIndex &parent
) const;
virtual int columnCount
(const QModelIndex &parent
) const;
int section,
Qt::Orientation orientation,
int role) const;
};
{
Q_OBJECT
public:
private:
Model m_model;
};
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;
};
To copy to clipboard, switch view to plain text mode
Test.cpp
Model::Model()
{
}
//
//-----------------------------------------------------------------------------
{
return 200;
}
//
//-----------------------------------------------------------------------------
int Model
::columnCount(const QModelIndex &parent
) const {
return 37;
}
//
//-----------------------------------------------------------------------------
{
if (role == Qt::DisplayRole)
{
.arg(index.row())
.arg(index.column()));
}
}
//
//-----------------------------------------------------------------------------
int section,
Qt::Orientation orientation,
int role) const
{
if (section < 37)
else
}
//
//-----------------------------------------------------------------------------
m_view(this)
{
setCentralWidget(&m_view);
m_view.setModel(&m_model);
m_view.verticalHeader()->setDefaultSectionSize(17);
}
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);
}
To copy to clipboard, switch view to plain text mode
I hope someone can help me.
Thanks in advance.
regards Marco B.
Bookmarks