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. updating model columns based on view update
Qt 6.11 is out! See what's new in the release blog

updating model columns based on view update

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.9k Views 1 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @user4592357 said in updating model columns based on view update:

    this list in model is not changed, i.e. columnCount() still returns the old 5.

    That's absolutely correct - you only hide a column in the view, you don't change the model. Why should the model change it's columnCount at all?

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    U 1 Reply Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      @user4592357 said in updating model columns based on view update:

      this list in model is not changed, i.e. columnCount() still returns the old 5.

      That's absolutely correct - you only hide a column in the view, you don't change the model. Why should the model change it's columnCount at all?

      U Offline
      U Offline
      user4592357
      wrote on last edited by
      #3

      @Christian-Ehrlicher said in updating model columns based on view update:

      Why should the model change it's columnCount at all?

      the problem is that, since model column count is the same, data() is called for those hidden columns.

      Christian EhrlicherC 1 Reply Last reply
      0
      • U user4592357

        @Christian-Ehrlicher said in updating model columns based on view update:

        Why should the model change it's columnCount at all?

        the problem is that, since model column count is the same, data() is called for those hidden columns.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @user4592357 Why is this a problem?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        U 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @user4592357 Why is this a problem?

          U Offline
          U Offline
          user4592357
          wrote on last edited by
          #5

          @Christian-Ehrlicher
          i have one column, which does some heavy calculation for data retrieval, so i wouldn't want extra work be done

          Christian EhrlicherC 1 Reply Last reply
          0
          • U user4592357

            @Christian-Ehrlicher
            i have one column, which does some heavy calculation for data retrieval, so i wouldn't want extra work be done

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @user4592357 You should not do the calculation inside the data() function.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            U 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @user4592357 You should not do the calculation inside the data() function.

              U Offline
              U Offline
              user4592357
              wrote on last edited by
              #7

              @Christian-Ehrlicher
              then where? if data() wants to retrieve that model index info, i need to provide the correct data, since i don't know whether column is hidden in gui or not

              JonBJ 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @user4592357 said in updating model columns based on view update:

                then where?

                When you fill the data into the model for example. data() is called very often and should do as less work as possible.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • U user4592357

                  @Christian-Ehrlicher
                  then where? if data() wants to retrieve that model index info, i need to provide the correct data, since i don't know whether column is hidden in gui or not

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #9

                  @user4592357
                  In view of @Christian-Ehrlicher's comments, you might consider adding a QProxyModel which hides the computed column from the outside world, makes life simpler.

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    user4592357
                    wrote on last edited by user4592357
                    #10

                    @Christian-Ehrlicher
                    okay, now i add the value of that column in a method filling tree node, only if the column is to be shown, because the computation of that data is slow.
                    now, if the column is hidden, and i show it, it doesn't display the data (because the logic of filling the node was done somewhere else)

                    JonBJ 1 Reply Last reply
                    0
                    • U user4592357

                      @Christian-Ehrlicher
                      okay, now i add the value of that column in a method filling tree node, only if the column is to be shown, because the computation of that data is slow.
                      now, if the column is hidden, and i show it, it doesn't display the data (because the logic of filling the node was done somewhere else)

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #11

                      @user4592357
                      I don't understand. If you allow for allow for hidden columns becoming shown, you have to write the logic to ensure the data is available. If necessary, react to the column being hidden/shown by refreshing the model or changing it or whatever is required to fetch the necessary data.

                      1 Reply Last reply
                      1

                      • Login

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