momesana
20th September 2009, 17:18
Hi,
I have a QTableModel with 5 columns, but when I return labels for more than 4 columns the horizontal headerview isn't shown at all. Here is a simple application to highlight the problem. Save it as main.cpp and compile it using qmake -project && qmake && make
#include <QtGui>
class TableModel : public QAbstractTableModel
{
Q_OBJECT
public:
TableModel(QObject* parent = 0) : QAbstractTableModel(parent)
{
}
protected:
protected:
int rowCount(const QModelIndex & parent = QModelIndex()) const
{
return 20;
}
int columnCount(const QModelIndex & parent = QModelIndex()) const
{
return 5;
}
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const
{
if (index.isValid() && role == Qt::DisplayRole) {
return QString("index: %1,%2").arg(index.row()).arg(index.column());
}
return QVariant();
}
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
{
if (orientation == Qt::Horizontal) {
switch(section) {
case 0: return QString("one");
case 1: return QString("two");
case 2: return QString("three");
case 3: return QString("four");
case 4: return QString("five");
}
}
return QVariant();
}
};
int main(int argc, char** argv)
{
QApplication app(argc, argv);
TableModel* model = new TableModel();
QTableView* view = new QTableView;
view->setModel(model);
view->show();
return app.exec();
}
#include "main.moc"
Any Ideas?
Thanx in advance
momesana
I have a QTableModel with 5 columns, but when I return labels for more than 4 columns the horizontal headerview isn't shown at all. Here is a simple application to highlight the problem. Save it as main.cpp and compile it using qmake -project && qmake && make
#include <QtGui>
class TableModel : public QAbstractTableModel
{
Q_OBJECT
public:
TableModel(QObject* parent = 0) : QAbstractTableModel(parent)
{
}
protected:
protected:
int rowCount(const QModelIndex & parent = QModelIndex()) const
{
return 20;
}
int columnCount(const QModelIndex & parent = QModelIndex()) const
{
return 5;
}
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const
{
if (index.isValid() && role == Qt::DisplayRole) {
return QString("index: %1,%2").arg(index.row()).arg(index.column());
}
return QVariant();
}
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
{
if (orientation == Qt::Horizontal) {
switch(section) {
case 0: return QString("one");
case 1: return QString("two");
case 2: return QString("three");
case 3: return QString("four");
case 4: return QString("five");
}
}
return QVariant();
}
};
int main(int argc, char** argv)
{
QApplication app(argc, argv);
TableModel* model = new TableModel();
QTableView* view = new QTableView;
view->setModel(model);
view->show();
return app.exec();
}
#include "main.moc"
Any Ideas?
Thanx in advance
momesana