我有一个QTableView对象,当我从showIndicators切换到showIndiValues时,我得到了这个丑陋的空标题行。问题在哪里?
void DBTableView::showIndicators()
{
enum {
indicators_Id = 0,
indicators_Name = 1,
indicators_CondName = 2,
indicators_MeasureName = 3,
indicators_Description = 4,
indicators_Responsible = 5
};
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT * FROM viewIndicators");
model->setHeaderData(indicators_Id, Qt::Horizontal, tr("ID"));
model->setHeaderData(indicators_Name, Qt::Horizontal, tr("Name"));
model->setHeaderData(indicators_CondName, Qt::Horizontal, tr("Condition Name"));
model->setHeaderData(indicators_MeasureName, Qt::Horizontal, tr("Measure"));
model->setHeaderData(indicators_Description, Qt::Horizontal, tr("Description"));
model->setHeaderData(indicators_Responsible, Qt::Horizontal, tr("Responsible"));
/* TableView part */
setModel(model);
hideColumn(indicators_Id);
QHeaderView *horizontalHeader = this->horizontalHeader();
horizontalHeader->setStretchLastSection(true);
QHeaderView *verticalHeader = this->verticalHeader();
verticalHeader->setStretchLastSection(true);
setSelectionBehavior(QAbstractItemView::SelectRows);
setColumnWidth(indicators_Id, 0);
setColumnWidth(indicators_Name, 400);
setColumnWidth(indicators_CondName, 120);
setColumnWidth(indicators_MeasureName, 120);
setColumnWidth(indicators_Description, 400);
createIndicatorContextMenu();
show();
}
void DBTableView::showIndiValues()
{
enum {
iv_Id = 0,
indicatorId = 1,
indicatorName = 2,
intervalName = 3,
iv_DataValue = 4,
iv_DataDate = 5,
iv_DataBirth = 6
};
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT * FROM viewIndiValues");
model->setHeaderData(iv_Id, Qt::Horizontal, tr("ID"));
model->setHeaderData(indicatorId, Qt::Horizontal, tr("Indicator ID"));
model->setHeaderData(indicatorName, Qt::Horizontal, tr("Indicator name"));
model->setHeaderData(intervalName, Qt::Horizontal, tr("Interval name"));
model->setHeaderData(iv_DataValue, Qt::Horizontal, tr("Value"));
model->setHeaderData(iv_DataDate, Qt::Horizontal, tr("Date"));
model->setHeaderData(iv_DataBirth, Qt::Horizontal, tr("Creation date"));
setModel(model);
hideColumn(iv_Id);
hideColumn(indicatorId);
QHeaderView *horizontalHeader = this->horizontalHeader();
horizontalHeader->setStretchLastSection(false);
QHeaderView *verticalHeader = this->verticalHeader();
verticalHeader->setStretchLastSection(false);
setSelectionBehavior(QAbstractItemView::SelectItems);
setColumnWidth(indicatorName, 400);
setColumnWidth(intervalName, 200);
setColumnWidth(iv_DataValue, 200);
setColumnWidth(iv_DataDate, 120);
setColumnWidth(iv_DataBirth, 120);
createIndiValueContextMenu();
show();
}
答案 0 :(得分:0)
我为QTableView制作了特殊功能,以清除以前型号的列。所以问题就消失了。