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 resize on edit

QSqlTableModel resize on edit

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 459 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.
  • Seb TurS Offline
    Seb TurS Offline
    Seb Tur
    wrote on last edited by
    #1

    Is there a way to resize the column to content after user put a proposed change in a cell but still hasn't submitted the change?
    So QSqlTableModel set to QTableView with ManulSubmit as the EditStrategy.
    A user enters cell but he cannot see entire text after he pressed enter.

    I can capture the setData that is triggered after submit but this is too late.
    I have set resizepolicy on view and on columns but it's not dynamic.

        sql_model_serie->setTable("DokSerieMag");
        sql_model_serie->select();
        ui->TV_serie->setModel(sql_model_serie);
        ui->TV_serie->hideColumn(ui->TV_serie->header_column("dokseria_id"));
        sql_model_serie->setEditStrategy(QSqlTableModel::OnManualSubmit);
    
        ui->TV_serie->resizeColumnsToContents();
    
        ui->TV_serie->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
    
        ui->TV_serie->horizontalHeader()->setResizeContentsPrecision(-1);
                for (int col = 0; col < ui->TV_serie->model()->columnCount(); ++col)
                    ui->TV_serie->resizeColumnToContents(col);
                ui->TV_serie->horizontalHeader()->setStretchLastSection(true);
    
    JonBJ 1 Reply Last reply
    0
    • Seb TurS Seb Tur

      Is there a way to resize the column to content after user put a proposed change in a cell but still hasn't submitted the change?
      So QSqlTableModel set to QTableView with ManulSubmit as the EditStrategy.
      A user enters cell but he cannot see entire text after he pressed enter.

      I can capture the setData that is triggered after submit but this is too late.
      I have set resizepolicy on view and on columns but it's not dynamic.

          sql_model_serie->setTable("DokSerieMag");
          sql_model_serie->select();
          ui->TV_serie->setModel(sql_model_serie);
          ui->TV_serie->hideColumn(ui->TV_serie->header_column("dokseria_id"));
          sql_model_serie->setEditStrategy(QSqlTableModel::OnManualSubmit);
      
          ui->TV_serie->resizeColumnsToContents();
      
          ui->TV_serie->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
      
          ui->TV_serie->horizontalHeader()->setResizeContentsPrecision(-1);
                  for (int col = 0; col < ui->TV_serie->model()->columnCount(); ++col)
                      ui->TV_serie->resizeColumnToContents(col);
                  ui->TV_serie->horizontalHeader()->setStretchLastSection(true);
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Seb-Tur
      FWIW did you try calling resizeColumnsToContents() again immediately after the user finished editing the cell?

      Seb TurS 1 Reply Last reply
      0
      • JonBJ JonB

        @Seb-Tur
        FWIW did you try calling resizeColumnsToContents() again immediately after the user finished editing the cell?

        Seb TurS Offline
        Seb TurS Offline
        Seb Tur
        wrote on last edited by
        #3

        @JonB

        I didn't find any onEditingFinshed signals
        I just found some other that are triggered only after data is submitted.
        Normally a user can edit multiple cells and hit Submit only after all of them are ready - in the meantime the edited ones that do not fit to column are truncated with ....

        Christian EhrlicherC JonBJ 2 Replies Last reply
        0
        • Seb TurS Seb Tur

          @JonB

          I didn't find any onEditingFinshed signals
          I just found some other that are triggered only after data is submitted.
          Normally a user can edit multiple cells and hit Submit only after all of them are ready - in the meantime the edited ones that do not fit to column are truncated with ....

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

          I would be rather annoyed when the cells would resizing during my edits... even afterwards it will not be a good ui design.

          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
          0
          • Seb TurS Seb Tur

            @JonB

            I didn't find any onEditingFinshed signals
            I just found some other that are triggered only after data is submitted.
            Normally a user can edit multiple cells and hit Submit only after all of them are ready - in the meantime the edited ones that do not fit to column are truncated with ....

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

            @Seb-Tur said in QSqlTableModel resize on edit:

            I didn't find any onEditingFinshed signals

            Search QAbstractItemView Class (inherited by your QTableView) for everything to do with itemDelegate. Then QAbstractItemDelegate Class for stuff to do with Editor/ModelData. This is how editing in a QTableView works. For your purpose you can hopefully avoid having to subclass to override virtual methods (though you could do that) by connecting to void QAbstractItemDelegate::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint = NoHint) signal?

            Seb TurS 1 Reply Last reply
            0
            • JonBJ JonB

              @Seb-Tur said in QSqlTableModel resize on edit:

              I didn't find any onEditingFinshed signals

              Search QAbstractItemView Class (inherited by your QTableView) for everything to do with itemDelegate. Then QAbstractItemDelegate Class for stuff to do with Editor/ModelData. This is how editing in a QTableView works. For your purpose you can hopefully avoid having to subclass to override virtual methods (though you could do that) by connecting to void QAbstractItemDelegate::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint = NoHint) signal?

              Seb TurS Offline
              Seb TurS Offline
              Seb Tur
              wrote on last edited by
              #6

              @JonB

              Thanks for the proposed solution , I will give it a try.

              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