Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableview column width is reset to default when model is change.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 2.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Pang
    wrote on last edited by
    #1

    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?

    raven-worxR Barry ScottB 2 Replies Last reply
    0
    • M Mr Pang

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @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?

        M Offline
        M Offline
        Mr Pang
        wrote on last edited by
        #3

        @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);
            }
        }
        
        raven-worxR 1 Reply Last reply
        0
        • M Mr Pang

          @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);
              }
          }
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @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.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          M 1 Reply Last reply
          4
          • raven-worxR raven-worx

            @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.

            M Offline
            M Offline
            Mr Pang
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • M Mr Pang

              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?

              Barry ScottB Offline
              Barry ScottB Offline
              Barry Scott
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              1
              • Barry ScottB Barry Scott

                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

                M Offline
                M Offline
                Mr Pang
                wrote on last edited by
                #7

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

                aha_1980A 1 Reply Last reply
                1
                • M Mr Pang

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

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by aha_1980
                  #8

                  @Mr-Pang @Barry-Scott

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

                  thanks

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved