#include #include #include #include class TableView : public QTableView { public: TableView(); }; TableView::TableView() { } //------------------------------------------------------------ class TableModel : public QAbstractTableModel { public: int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; }; int TableModel::rowCount(const QModelIndex &parent) const { return 100; } int TableModel::columnCount(const QModelIndex &parent) const { return 1; } QVariant TableModel::data(const QModelIndex &index, int role) const { switch (role) { case Qt::DisplayRole: if (index.row() % 3 == 0) return "1234567890qwertyuioasdfgh"; if (index.row() % 3 == 1) return "1234567890"; return "zxcvbn"; case Qt::TextAlignmentRole: return int(Qt::AlignRight | Qt::AlignVCenter); //return int(Qt::AlignLeft | Qt::AlignVCenter); } return QVariant{}; } //------------------------------------------------------------ int main(int argc, char ** argv) { QApplication app(argc, argv); TableModel m; TableView v; v.setModel(&m); v.show(); return app.exec(); }