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. [solved]Disabling editing on certain columns in QSqlTableModel
Forum Updated to NodeBB v4.3 + New Features

[solved]Disabling editing on certain columns in QSqlTableModel

Scheduled Pinned Locked Moved General and Desktop
qsqltablemodelsqlqt5.0.2
9 Posts 2 Posters 4.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.
  • C Offline
    C Offline
    chronix
    wrote on last edited by chronix
    #1

    Hey,
    I was working with QSqlTableModel, and I was wondering is there a way that we can disable editing on a certain columns, also on some other column can I receive a signal when user double clicks to make changes, so that I can execute some set of codes.
    Thanks in advance. :)

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

      Hi,

      You need to subclass QSqlTableModel and reimplement the flags method

      Do you mean something like the doubleClicked signal ?

      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
      • C Offline
        C Offline
        chronix
        wrote on last edited by
        #3

        @SGaist said:

        Hi,

        You need to subclass QSqlTableModel and reimplement the flags method

        Do you mean something like the doubleClicked signal ?

        Hey SGaist, thanks for replying
        Ok i need to learn subclassing, any tuts?
        also, there are some fields i want to the user edit but i want to keeps its back up, also change others things with respect to the edits made by user, i guess i can use doubleClicked signal.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chronix
          wrote on last edited by
          #4

          Ok i did the subclassing part, thanks a lot :D

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

            If you want to react on the modified data, then you should rather check the model's dataChanged signal

            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
            • C Offline
              C Offline
              chronix
              wrote on last edited by chronix
              #6

              @SGaist said:

              If you want to react on the modified data, then you should rather check the model's dataChanged signal

              this->connect(modelC, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChangedEdit(QModelIndex a,QModelIndex b)));

              here modelC is the subclassed QSqlTableModel and dataChangedEdit is the Slot with I declared bt it doesn't work, whats wrong?

              Also it says, QObject::connect: No such slot MainWindow::dataChangedEdit(QModelIndex a,QModelIndex b) in ....

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

                Remove a and b from your connect statement, only the type of the parameter should be there not their name. If using Qt 5, you should consider using the new syntax.

                Also note that dataChangeEdit should rather be dataChangedEdit(const QModelIndex& a, const QModelIndex& b) that will avoid needles copies

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

                C 1 Reply Last reply
                0
                • SGaistS SGaist

                  Remove a and b from your connect statement, only the type of the parameter should be there not their name. If using Qt 5, you should consider using the new syntax.

                  Also note that dataChangeEdit should rather be dataChangedEdit(const QModelIndex& a, const QModelIndex& b) that will avoid needles copies

                  C Offline
                  C Offline
                  chronix
                  wrote on last edited by
                  #8

                  thank you @SGaist, it works. :)
                  i'll look into the new syntax.

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

                    You're welcome !

                    Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                    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

                    • Login

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