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. QSqlTableModel change underling structure
Qt 6.11 is out! See what's new in the release blog

QSqlTableModel change underling structure

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.1k 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.
  • Dan3460D Offline
    Dan3460D Offline
    Dan3460
    wrote on last edited by
    #1

    I have a model that connects to a single table, this table will change the number of columns depending on certain conditions during the execution of the program. The model is connected to a QTableView.
    I have a function that controls the number of columns at the end of the function i have a call to model->select(), to update the information of the model and tableView->reset(), to what i thought would rearrange the view adding or taking away columns.
    The problem is that the view does not change from the original number of columns that it had. If i reduce the number i can see that the data change and show empty on the missing columns. Is there a command for the tableView to resize it self?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What kind of conditions ?
      What does exactly change ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Dan3460D Offline
        Dan3460D Offline
        Dan3460
        wrote on last edited by
        #3

        The number of columns in the underling table changes. This is the sequence.
        1- in the constructor a SQLTablemodel is created over a table that has 5 columns.
        2-In the same constructor the model is displayed on a tableview. You can see all 5 columns.
        3-The underling table is changed to 3 columns, or to 7 columns.
        4. On the first case, the tableview shows data on the first 3 columns and the name of the old columns in column 4 and 5. On the second case the tableview still shows only 5 columns, with the new data.

        artwawA 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How are you changing the underlying table ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Dan3460D Dan3460

            The number of columns in the underling table changes. This is the sequence.
            1- in the constructor a SQLTablemodel is created over a table that has 5 columns.
            2-In the same constructor the model is displayed on a tableview. You can see all 5 columns.
            3-The underling table is changed to 3 columns, or to 7 columns.
            4. On the first case, the tableview shows data on the first 3 columns and the name of the old columns in column 4 and 5. On the second case the tableview still shows only 5 columns, with the new data.

            artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #5

            @Dan3460 Hi, I had similar problems and solved them by manipulating associated QHeaderView (methods showColumn() and hideColumn()).

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0
            • Dan3460D Offline
              Dan3460D Offline
              Dan3460
              wrote on last edited by
              #6

              @artwaw yes that is the way i solved the problem. I setup a set number of columns and i hide and unhide columns. Thanks

              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