tags:

views:

40

answers:

1

I have one QTableView object and when I am switching from showIndicators to showIndiValues I am getting this ugly empty header line. Where is the problem?

alt text

 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();
}
A: 

I've made special function for QTableView to clear columns from previous models. So the problem gone away.

DragonionS