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, QSqlTableModel and programmaticaly insert inew row.
Forum Updated to NodeBB v4.3 + New Features

QTableView, QSqlTableModel and programmaticaly insert inew row.

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.7k 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.
  • A Offline
    A Offline
    aliks-os
    wrote on last edited by
    #1

    According Qt documentation:
    If you insert row programmatically using QSqlTableModel::insertRows(), the new rows will be marked with an asterisk (*) until they are submitted using submitAll() or automatically when the user moves to another record (assuming the edit strategy is QSqlTableModel::OnRowChange).

    My situation:
    I insert new row programmatically using QSqlTableModel::insertRowIntoTable(rec), so I not necessary using submitAll(). Edit strategy is OnManualSubmit. All works fine, but when I insert new row, in the QTableView the new rows are marked with an asterisk (). How I may the remove an asterisk () with out using submitAll() and reloading model???

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Without any research, so I may be totally off:
      My first guess would be that the asterisk is created by the virtual headerData method. If that is the case, you can simply subclass QSqlTableModel, reimplement headerData(), and don't show the asterisk.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        octal
        wrote on last edited by
        #3

        bq. Without any research, so I may be totally off:

        No you're not :D

        The asterisk is returned by the headerData() model data, see "headerData":http://qt.gitorious.org/qt/qt/blobs/de07df9001586cc18ae267591359541b7ea494a0/src/sql/models/qsqltablemodel.cpp#line459

        So one solution would be, as Andre said, to subclass QSqlTableModel to override the headerData function.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aliks-os
          wrote on last edited by
          #4

          Well...Many thaks!

          @
          bool asterisc;

          QVariant SQLModel::headerData ( int section, Qt::Orientation orientation, int role ) const {
          if (orientation == Qt::Vertical) {
          if (asterisc && QSqlTableModel::headerData(section,Qt::Vertical) == "*") {
          return this->rowCount();
          } else return QSqlTableModel::headerData(section,orientation, role);
          } else return QSqlTableModel::headerData(section,orientation, role);
          }
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Slightly shorter:

            @
            bool asterisc;

            QVariant SQLModel::headerData ( int section, Qt::Orientation orientation, int role ) const {
            if (orientation == Qt::Vertical) {
            if (asterisc && QSqlTableModel::headerData(section,Qt::Vertical) == "*") {
            return this->rowCount();
            }
            }

            return QSqlTableModel::headerData(section,orientation, role);
            

            }
            @

            And you don't really need to check if you currently have an askterisk either, so you could return to this:
            @
            bool asterisc;

            QVariant SQLModel::headerData ( int section, Qt::Orientation orientation, int role ) const {
            if (asterisc && orientation == Qt::Vertical) {
            return this->rowCount();
            }

            return QSqlTableModel::headerData(section,orientation, role);
            

            }
            @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aliks-os
              wrote on last edited by
              #6

              OK many 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