#include <QtGui>
{
public:
TableModel
(int rows,
int cols,
QObject* parent
= 0)
int rowCount
(const QModelIndex
& parent
= QModelIndex()) const { return rows;
} int columnCount
(const QModelIndex
& parent
= QModelIndex()) const { return cols;
}
QVariant data
(const QModelIndex
& index,
int role
= Qt
::DisplayRole) const {
if (index.isValid() && role == Qt::DisplayRole)
return QString("%1,%2").
arg(index.
row()).
arg(index.
column());
}
private:
int rows;
int cols;
};
int main(int argc, char *argv[])
{
combo.setModel(new TableModel(5, 2, &combo));
combo.show();
return app.exec();
}
#include <QtGui>
class TableModel : public QAbstractTableModel
{
public:
TableModel(int rows, int cols, QObject* parent = 0)
: QAbstractTableModel(parent), rows(rows), cols(cols) { }
int rowCount(const QModelIndex& parent = QModelIndex()) const { return rows; }
int columnCount(const QModelIndex& parent = QModelIndex()) const { return cols; }
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const
{
if (index.isValid() && role == Qt::DisplayRole)
return QString("%1,%2").arg(index.row()).arg(index.column());
return QVariant();
}
private:
int rows;
int cols;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QComboBox combo;
combo.setModel(new TableModel(5, 2, &combo));
combo.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks