效果图:
#include <QicsTable.h>
#include <QicsDataModelDefault.h>
#include <QVBoxLayout>
Demo1::Demo1(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
const int numRows = 10;
const int numCols = 5;
// create the data model
QicsDataModel* dm = new QicsDataModelDefault(numRows, numCols);
// populate the data model with some data
for (int i = 0; i < numRows; ++i)
for (int j = 0; j < numCols; ++j)
dm->setItem(i, j, QicsDataInt(i * j));
// create the table, using the data model we created above
QicsTable* table = new QicsTable(dm, 0);
// table->setWindowTitle(QObject::tr("Hello World Table Example"));
// make sure the table is only as large as necessary
table->setVisibleRows(numRows);
table->setVisibleColumns(numCols);
//table->setTopHeaderVisible(false);
table->setLeftHeaderVisible(false);
//table->setDefaultRowHeightInPixels(24);
//table->setDefaultColumnWidthInPixels(24);
table->setSelectionPolicy(Qics::SelectNone);
table->mainGridRef().setReadOnly(true);
table->mainGridRef().setAlignment(Qt::AlignCenter);
table->mainGridRef().setFont(QFont("Helvetica", 12, QFont::Bold));
//table->setHScrollBarMode(Qics::AlwaysOff);
//table->setVScrollBarMode(Qics::AlwaysOff);
// Add a title widget to the top of the table
/*QLabel* label = new QLabel(QObject::tr("Hello World, Table"), table);
label->setAlignment(Qt::AlignCenter);
table->setTopTitleWidget(label);*/
ui.verticalLayout->addWidget(table);
}
Demo1::~Demo1()
{}
备注:
table->setTopHeaderVisible(false); // 隐藏上测列头
table->setLeftHeaderVisible(false);// 隐藏左侧列头