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 Update on Monday, May 27th 2025

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
  • 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 12 Feb 2018, 07:30 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?

    R B 2 Replies Last reply 12 Feb 2018, 08:00
    0
    • M Mr Pang
      12 Feb 2018, 07:30

      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?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 12 Feb 2018, 08:00 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 12 Feb 2018, 08:02
      1
      • R raven-worx
        12 Feb 2018, 08:00

        @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 12 Feb 2018, 08:02 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);
            }
        }
        
        R 1 Reply Last reply 12 Feb 2018, 08:05
        0
        • M Mr Pang
          12 Feb 2018, 08:02

          @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);
              }
          }
          
          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 12 Feb 2018, 08:05 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 12 Feb 2018, 08:10
          4
          • R raven-worx
            12 Feb 2018, 08:05

            @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 12 Feb 2018, 08:10 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
              12 Feb 2018, 07:30

              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?

              B Offline
              B Offline
              Barry Scott
              wrote on 12 Feb 2018, 20:09 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 23 Feb 2018, 05:10
              1
              • B Barry Scott
                12 Feb 2018, 20:09

                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 23 Feb 2018, 05:10 last edited by
                #7

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

                aha_1980A 1 Reply Last reply 23 Feb 2018, 06:09
                1
                • M Mr Pang
                  23 Feb 2018, 05:10

                  @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 23 Feb 2018, 06:09 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