QTableview column width is reset to default when model is change.



  • Hi,
    I have a qtableview, some columns has a long string. So I need to resize the width of column. But when model adds new item, or item is updated. The column width is reset to default. I don't want so.
    How to due with this?


  • Moderators

    @Mr-Pang
    first of all you need to be more specific.
    What type of model? Custom implementation?
    If it's a custom implemented model, do you call reset() whenever item data changes?



  • @raven-worx
    It is QStandardItemModel.

    void MainWindow::updateModel(int row, Session *s)
    {
        int i=0;
        QStringList stat;
        stat << "INACTIVE" << "ACTIVE" << "REJECTED";
        ue_list_model->setItem(row, i++, new QStandardItem(stat[s->getStat()]));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getImsi().getImsiString()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getApn().getApn()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getRFTeidC().getFTeid()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getDefaultBearer()->getRFTeidU().getFTeid()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getLFTeidC().getFTeid()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getDefaultBearer()->getLFTeidU().getFTeid()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getPaa().getPaa()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getRatType().getRatType()));
        ue_list_model->setItem(row, i++, new QStandardItem(s->getBearersEbi()));
        model_map[s] = ue_list_model->item(row);
        ue_list_model->item(row)->setData(QVariant::fromValue(s));
    
        for(int j=0;j<i;j++){
            ue_list_model->item(row, j)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemNeverHasChildren);
        }
    }
    

  • Moderators

    @Mr-Pang
    why do you mix ue_list_model->setItem() when you already use ue_list_model->item() in the same function?`
    I guess setting a new item leads to a model reset, whereas updating an existing item just triggers a data changed.



  • @raven-worx
    Here may insert a new row. If I want to add a new row, I will call this function with updateModel(ue_list_model->rowCount(), s);
    So item may not existing yet.



  • Does the column width reset when your app gets focus as well?

    I am seeing this after updating from Qt 5.9.3 to Qt 5.9.4 on Fedora.

    Barry



  • @Barry-Scott
    Oh, Yes. It a new bug in 5.9.4


  • Qt Champions 2018

    @Mr-Pang @Barry-Scott

    Have you already searched on bugreports.qt.io? if this bug is not reported yet, please do so.

    thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.