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. QSqlRelationalTableModel with multiple Joins?
Forum Updated to NodeBB v4.3 + New Features

QSqlRelationalTableModel with multiple Joins?

Scheduled Pinned Locked Moved Unsolved General and Desktop
67 Posts 4 Posters 25.3k 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.
  • D Offline
    D Offline
    devhobby
    wrote on 7 Feb 2018, 21:28 last edited by
    #9

    I wanted to take a different approach:

    Send a custom query to the table view in read-only mode

    Then, a right click (or another method) will change the content of the record through code.

    The problem is: I can't even send a custom query!

    My query (similar to the one I posted above) has some joins in it.

    But why can't I use the table returned by a query as the table to display on the Table View?

    Is all this really so limited?

    J 1 Reply Last reply 7 Feb 2018, 21:36
    0
    • D devhobby
      7 Feb 2018, 21:28

      I wanted to take a different approach:

      Send a custom query to the table view in read-only mode

      Then, a right click (or another method) will change the content of the record through code.

      The problem is: I can't even send a custom query!

      My query (similar to the one I posted above) has some joins in it.

      But why can't I use the table returned by a query as the table to display on the Table View?

      Is all this really so limited?

      J Offline
      J Offline
      JonB
      wrote on 7 Feb 2018, 21:36 last edited by
      #10

      @devhobby
      You are using a QTableView, right? You can use that against a QSqlQueryModel, which is a model based against a query rather than an actual table.

      D 1 Reply Last reply 7 Feb 2018, 21:47
      0
      • J JonB
        7 Feb 2018, 21:36

        @devhobby
        You are using a QTableView, right? You can use that against a QSqlQueryModel, which is a model based against a query rather than an actual table.

        D Offline
        D Offline
        devhobby
        wrote on 7 Feb 2018, 21:47 last edited by devhobby 2 Jul 2018, 22:08
        #11

        @JonB said in QSqlRelationalTableModel with multiple Joins?:

        @devhobby
        You are using a QTableView, right? You can use that against a QSqlQueryModel, which is a model based against a query rather than an actual table.

        No, I'm using a QSqlQueryModel

                _queryModel = new QSqlQueryModel(ui->tableView);
        
               _queryModel->setQuery("SELECT Employee.id, Employee.Name, Employee.Surname, Birthplace.Name as 'Birthplace', Employee.Birthdate, Residence.Name as 'Residence', Employee.Qualification, Position.Name as 'Position', EmployeePosition.EngagementDate, Resource.Name as 'Resource', EmployeeResource.AcquisitionDate"
                            "FROM Employee"
                            "LEFT JOIN EmployeePosition ON Employee.id = EmployeePosition.idEmployee"
                            "LEFT JOIN Position ON EmployeePosition.idPosition = Position.id"
        
                            "LEFT JOIN EmployeeResource ON Employee.id = EmployeeResource.idEmployee"
                            "LEFT JOIN Resource ON Resource.id = EmployeeResource.idResource"
        
                            "LEFT JOIN Country AS Birthplace ON Employee.BirthplaceID = Birthplace.id"
                            "LEFT JOIN Country AS Residence ON Employee.ResidenceID = Residence.id", *_db);
        
                ui->tableView->setModel(_queryModel);
                ui->tableView->show();
        

        And the Table View is blank

        I also tried with QSqlTableModel

                _tableModel = new QSqlTableModel(ui->tableView, *_db);
        
                QString myQuery = "SELECT Employee.id, Employee.Name, Employee.Surname, Birthplace.Name as 'Birthplace', Employee.Birthdate, Residence.Name as 'Residence', Employee.Qualification, Position.Name as 'Position', EmployeePosition.EngagementDate, Resource.Name as 'Resource', EmployeeResource.AcquisitionDate"
                                "FROM Employee"
                                "LEFT JOIN EmployeePosition ON Employee.id = EmployeePosition.idEmployee"
                                "LEFT JOIN Position ON EmployeePosition.idPosition = Position.id"
        
                                "LEFT JOIN EmployeeResource ON Employee.id = EmployeeResource.idEmployee"
                                "LEFT JOIN Resource ON Resource.id = EmployeeResource.idResource"
        
                                "LEFT JOIN Country AS Birthplace ON Employee.BirthplaceID = Birthplace.id"
                                "LEFT JOIN Country AS Residence ON Employee.ResidenceID = Residence.id";
        
                _tableModel->setTable(myQuery );
                _tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
                _tableModel->select();
        
                ui->tableView->setModel(_tableModel);
                ui->tableView->show();
        

        Same issue: Table View is blank.

        J 1 Reply Last reply 7 Feb 2018, 22:54
        0
        • D devhobby
          7 Feb 2018, 21:47

          @JonB said in QSqlRelationalTableModel with multiple Joins?:

          @devhobby
          You are using a QTableView, right? You can use that against a QSqlQueryModel, which is a model based against a query rather than an actual table.

          No, I'm using a QSqlQueryModel

                  _queryModel = new QSqlQueryModel(ui->tableView);
          
                 _queryModel->setQuery("SELECT Employee.id, Employee.Name, Employee.Surname, Birthplace.Name as 'Birthplace', Employee.Birthdate, Residence.Name as 'Residence', Employee.Qualification, Position.Name as 'Position', EmployeePosition.EngagementDate, Resource.Name as 'Resource', EmployeeResource.AcquisitionDate"
                              "FROM Employee"
                              "LEFT JOIN EmployeePosition ON Employee.id = EmployeePosition.idEmployee"
                              "LEFT JOIN Position ON EmployeePosition.idPosition = Position.id"
          
                              "LEFT JOIN EmployeeResource ON Employee.id = EmployeeResource.idEmployee"
                              "LEFT JOIN Resource ON Resource.id = EmployeeResource.idResource"
          
                              "LEFT JOIN Country AS Birthplace ON Employee.BirthplaceID = Birthplace.id"
                              "LEFT JOIN Country AS Residence ON Employee.ResidenceID = Residence.id", *_db);
          
                  ui->tableView->setModel(_queryModel);
                  ui->tableView->show();
          

          And the Table View is blank

          I also tried with QSqlTableModel

                  _tableModel = new QSqlTableModel(ui->tableView, *_db);
          
                  QString myQuery = "SELECT Employee.id, Employee.Name, Employee.Surname, Birthplace.Name as 'Birthplace', Employee.Birthdate, Residence.Name as 'Residence', Employee.Qualification, Position.Name as 'Position', EmployeePosition.EngagementDate, Resource.Name as 'Resource', EmployeeResource.AcquisitionDate"
                                  "FROM Employee"
                                  "LEFT JOIN EmployeePosition ON Employee.id = EmployeePosition.idEmployee"
                                  "LEFT JOIN Position ON EmployeePosition.idPosition = Position.id"
          
                                  "LEFT JOIN EmployeeResource ON Employee.id = EmployeeResource.idEmployee"
                                  "LEFT JOIN Resource ON Resource.id = EmployeeResource.idResource"
          
                                  "LEFT JOIN Country AS Birthplace ON Employee.BirthplaceID = Birthplace.id"
                                  "LEFT JOIN Country AS Residence ON Employee.ResidenceID = Residence.id";
          
                  _tableModel->setTable(myQuery );
                  _tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
                  _tableModel->select();
          
                  ui->tableView->setModel(_tableModel);
                  ui->tableView->show();
          

          Same issue: Table View is blank.

          J Offline
          J Offline
          JonB
          wrote on 7 Feb 2018, 22:54 last edited by JonB 2 Jul 2018, 23:32
          #12

          @devhobby
          I was asking you to confirm that in ui->tableView->setModel(_queryModel); the type of your ui->tableView is a QTableView?

          Anyway, assuming it is, what's this:

           _queryModel = new QSqlQueryModel(ui->tableView);
          

          What's that parent doing there? (Haven't seen this before, just checking.)

          Does QSqlQueryModel::lastError() tell you anything after setQuery() or later?

          Hang on! I don't do C++, but the way you've written your query, does C++ join the strings with a space between? Because if not (and I don't think it does) your words are all touching each other, and you have a SQL error!! Make sure your query is right, and check that lastError() thing, e.g.

          QSqlQueryModel model;
          model.setQuery("select *"
                         "from MyTable");
          if (model.lastError().isValid())
              qDebug() << model.lastError();
          

          Because I think the principle should be working fine otherwise.

          D 1 Reply Last reply 8 Feb 2018, 14:45
          3
          • J JonB
            7 Feb 2018, 22:54

            @devhobby
            I was asking you to confirm that in ui->tableView->setModel(_queryModel); the type of your ui->tableView is a QTableView?

            Anyway, assuming it is, what's this:

             _queryModel = new QSqlQueryModel(ui->tableView);
            

            What's that parent doing there? (Haven't seen this before, just checking.)

            Does QSqlQueryModel::lastError() tell you anything after setQuery() or later?

            Hang on! I don't do C++, but the way you've written your query, does C++ join the strings with a space between? Because if not (and I don't think it does) your words are all touching each other, and you have a SQL error!! Make sure your query is right, and check that lastError() thing, e.g.

            QSqlQueryModel model;
            model.setQuery("select *"
                           "from MyTable");
            if (model.lastError().isValid())
                qDebug() << model.lastError();
            

            Because I think the principle should be working fine otherwise.

            D Offline
            D Offline
            devhobby
            wrote on 8 Feb 2018, 14:45 last edited by devhobby 2 Aug 2018, 14:50
            #13

            @JonB said in QSqlRelationalTableModel with multiple Joins?:
            does C++ join the strings with a space between? Because if not (and I don't think it does) your words are all touching each other, >and you have a SQL error!! Make sure your query is right, and check that lastError() thing, e.g.
            Because I think the principle should be working fine otherwise.

            Oh gosh! I completely forgot to put the spaces before each line! Thanks

            By the way, once that I get all of this setup... now I need to find a way to customize a cell (item).
            I successfully retrieve its index... but I'd like to change its background color, for instance

            And since I'm using a Table View and not a Table Widget, I only see item delegates.

            How can I achieve what I want?

            1 Reply Last reply
            1
            • V Offline
              V Offline
              VRonin
              wrote on 8 Feb 2018, 15:23 last edited by
              #14

              See https://forum.qt.io/topic/85973/how-to-simply-change-the-background-colour-of-a-cell-inside-a-tableview

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              D 1 Reply Last reply 8 Feb 2018, 15:50
              2
              • V VRonin
                8 Feb 2018, 15:23

                See https://forum.qt.io/topic/85973/how-to-simply-change-the-background-colour-of-a-cell-inside-a-tableview

                D Offline
                D Offline
                devhobby
                wrote on 8 Feb 2018, 15:50 last edited by
                #15

                @VRonin said in QSqlRelationalTableModel with multiple Joins?:

                See https://forum.qt.io/topic/85973/how-to-simply-change-the-background-colour-of-a-cell-inside-a-tableview

                Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

                I just want to change the data of the cell and, once changed, color that cell in a different color to alert the user of the change of that particular item/cell.

                Seems a lot of hard-coding work... maybe I should find another convenient way... but for now let's see what comes out

                J V 2 Replies Last reply 8 Feb 2018, 16:31
                0
                • D devhobby
                  8 Feb 2018, 15:50

                  @VRonin said in QSqlRelationalTableModel with multiple Joins?:

                  See https://forum.qt.io/topic/85973/how-to-simply-change-the-background-colour-of-a-cell-inside-a-tableview

                  Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

                  I just want to change the data of the cell and, once changed, color that cell in a different color to alert the user of the change of that particular item/cell.

                  Seems a lot of hard-coding work... maybe I should find another convenient way... but for now let's see what comes out

                  J Offline
                  J Offline
                  JonB
                  wrote on 8 Feb 2018, 16:31 last edited by
                  #16

                  @devhobby
                  If you want to edit in a QTableView (right?), what have you set your http://doc.qt.io/qt-5/qabstractitemview.html#editTriggers-prop to?

                  D 1 Reply Last reply 8 Feb 2018, 16:37
                  1
                  • J JonB
                    8 Feb 2018, 16:31

                    @devhobby
                    If you want to edit in a QTableView (right?), what have you set your http://doc.qt.io/qt-5/qabstractitemview.html#editTriggers-prop to?

                    D Offline
                    D Offline
                    devhobby
                    wrote on 8 Feb 2018, 16:37 last edited by
                    #17

                    @JonB said in QSqlRelationalTableModel with multiple Joins?:

                    @devhobby
                    If you want to edit in a QTableView (right?), what have you set your http://doc.qt.io/qt-5/qabstractitemview.html#editTriggers-prop to?

                    QAbstractItemView::DoubleClicked

                    ui->tableView->setModel(_queryModel);
                    ui->tableView->verticalHeader()->hide();
                    ui->tableView->setEditTriggers(QAbstractItemView::DoubleClicked);
                    ui->tableView->show();
                    
                    J 1 Reply Last reply 8 Feb 2018, 16:44
                    0
                    • D devhobby
                      8 Feb 2018, 16:37

                      @JonB said in QSqlRelationalTableModel with multiple Joins?:

                      @devhobby
                      If you want to edit in a QTableView (right?), what have you set your http://doc.qt.io/qt-5/qabstractitemview.html#editTriggers-prop to?

                      QAbstractItemView::DoubleClicked

                      ui->tableView->setModel(_queryModel);
                      ui->tableView->verticalHeader()->hide();
                      ui->tableView->setEditTriggers(QAbstractItemView::DoubleClicked);
                      ui->tableView->show();
                      
                      J Offline
                      J Offline
                      JonB
                      wrote on 8 Feb 2018, 16:44 last edited by JonB 2 Aug 2018, 16:45
                      #18

                      @devhobby
                      And you are saying that when you double-click...? Nothing at all happens?

                      If that is the case, I can only imagine your model is read-only, to do with it being a SELECT and not a table? To be clear, you won't be "changing the data of the cell" per se, you'll be changing the data in the model that cell is displaying.

                      D 1 Reply Last reply 8 Feb 2018, 16:50
                      0
                      • J JonB
                        8 Feb 2018, 16:44

                        @devhobby
                        And you are saying that when you double-click...? Nothing at all happens?

                        If that is the case, I can only imagine your model is read-only, to do with it being a SELECT and not a table? To be clear, you won't be "changing the data of the cell" per se, you'll be changing the data in the model that cell is displaying.

                        D Offline
                        D Offline
                        devhobby
                        wrote on 8 Feb 2018, 16:50 last edited by devhobby 2 Aug 2018, 16:51
                        #19

                        @JonB said in QSqlRelationalTableModel with multiple Joins?:

                        @devhobby
                        And you are saying that when you double-click...? Nothing at all happens?

                        If that is the case, I can only imagine your model is read-only, to do with it being a SELECT and not a table?

                        Yes, as stated above I used my custom query to do all the joins.

                        By the way, I don't expect to change the database directly.

                        I just want to visually edit the cell without applying any changes to the database.

                        Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

                        When the user presses the button "Commit changes" I will have a series of changes that the user wants to apply to the database -> I now need to make them real sending a custom query to the database.

                        J 1 Reply Last reply 8 Feb 2018, 16:54
                        0
                        • D devhobby
                          8 Feb 2018, 16:50

                          @JonB said in QSqlRelationalTableModel with multiple Joins?:

                          @devhobby
                          And you are saying that when you double-click...? Nothing at all happens?

                          If that is the case, I can only imagine your model is read-only, to do with it being a SELECT and not a table?

                          Yes, as stated above I used my custom query to do all the joins.

                          By the way, I don't expect to change the database directly.

                          I just want to visually edit the cell without applying any changes to the database.

                          Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

                          When the user presses the button "Commit changes" I will have a series of changes that the user wants to apply to the database -> I now need to make them real sending a custom query to the database.

                          J Offline
                          J Offline
                          JonB
                          wrote on 8 Feb 2018, 16:54 last edited by JonB 2 Aug 2018, 16:55
                          #20

                          @devhobby
                          I'm a little lost. You wrote:

                          Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

                          I thought you were saying when double-click it does not let you edit, nothing happens, or whatever. Now I think you're saying it does let you edit? I don't know if you have a question here?

                          D 1 Reply Last reply 8 Feb 2018, 16:56
                          0
                          • J JonB
                            8 Feb 2018, 16:54

                            @devhobby
                            I'm a little lost. You wrote:

                            Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

                            I thought you were saying when double-click it does not let you edit, nothing happens, or whatever. Now I think you're saying it does let you edit? I don't know if you have a question here?

                            D Offline
                            D Offline
                            devhobby
                            wrote on 8 Feb 2018, 16:56 last edited by devhobby 2 Aug 2018, 16:58
                            #21

                            @JonB said in QSqlRelationalTableModel with multiple Joins?:

                            @devhobby
                            I'm a little lost. You wrote:

                            Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

                            I thought you were saying when double-click it does not let you edit, nothing happens, or whatever. Now I think you're saying it does let you edit? I don't know if you have a question here?

                            Yes I asked if there's a way to change the content of the cell by directly typing into it

                            Because now, when I double click, nothing happens.

                            Once the cell is edited, I'd also like to change its background color... but that's another story

                            J 1 Reply Last reply 8 Feb 2018, 17:01
                            0
                            • D devhobby
                              8 Feb 2018, 16:56

                              @JonB said in QSqlRelationalTableModel with multiple Joins?:

                              @devhobby
                              I'm a little lost. You wrote:

                              Thanks but before doing that, I was wondering if there's a way to change the content of the cell by directly typing into it.

                              I thought you were saying when double-click it does not let you edit, nothing happens, or whatever. Now I think you're saying it does let you edit? I don't know if you have a question here?

                              Yes I asked if there's a way to change the content of the cell by directly typing into it

                              Because now, when I double click, nothing happens.

                              Once the cell is edited, I'd also like to change its background color... but that's another story

                              J Offline
                              J Offline
                              JonB
                              wrote on 8 Feb 2018, 17:01 last edited by
                              #22

                              @devhobby said in QSqlRelationalTableModel with multiple Joins?:

                              Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

                              Because now, when I double click, nothing happens.

                              Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

                              D 1 Reply Last reply 8 Feb 2018, 17:04
                              1
                              • J JonB
                                8 Feb 2018, 17:01

                                @devhobby said in QSqlRelationalTableModel with multiple Joins?:

                                Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

                                Because now, when I double click, nothing happens.

                                Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

                                D Offline
                                D Offline
                                devhobby
                                wrote on 8 Feb 2018, 17:04 last edited by
                                #23

                                @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                @devhobby said in QSqlRelationalTableModel with multiple Joins?:

                                Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

                                Because now, when I double click, nothing happens.

                                Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

                                Don't worry! I'm sorry, I'm probably using the wrong tenses to express myself.

                                "Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString"

                                Is the prediction of what I want to happen... and can't manage to make it happen actually

                                J 1 Reply Last reply 8 Feb 2018, 17:07
                                1
                                • D devhobby
                                  8 Feb 2018, 17:04

                                  @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                  @devhobby said in QSqlRelationalTableModel with multiple Joins?:

                                  Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString

                                  Because now, when I double click, nothing happens.

                                  Sorry, but if "nothing happens" when you double-click cell to edit, how come you talk about "Once the user changes the text of the cell"? Maybe I'm being dumb, but I just don't get it!

                                  Don't worry! I'm sorry, I'm probably using the wrong tenses to express myself.

                                  "Once the user changes the text of the cell, the new text is immediately visible and I store it in a QString"

                                  Is the prediction of what I want to happen... and can't manage to make it happen actually

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 8 Feb 2018, 17:07 last edited by JonB 2 Aug 2018, 17:07
                                  #24

                                  @devhobby

                                  Is the prediction of what I want to happen... and can't manage to make it happen actually

                                  Ohhhh...! :)

                                  OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

                                  I shall step aside and you need an expert here to guide you further....

                                  D 1 Reply Last reply 8 Feb 2018, 17:09
                                  1
                                  • J JonB
                                    8 Feb 2018, 17:07

                                    @devhobby

                                    Is the prediction of what I want to happen... and can't manage to make it happen actually

                                    Ohhhh...! :)

                                    OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

                                    I shall step aside and you need an expert here to guide you further....

                                    D Offline
                                    D Offline
                                    devhobby
                                    wrote on 8 Feb 2018, 17:09 last edited by devhobby 2 Aug 2018, 17:09
                                    #25

                                    @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                    @devhobby

                                    Is the prediction of what I want to happen... and can't manage to make it happen actually

                                    Ohhhh...! :)

                                    OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

                                    I shall step aside and you need an expert here to guide you further....

                                    Yes, the custom query is most likely keeping my Table View read-only.

                                    I just want to visually edit the cells...

                                    This is far more complicated than I thought...

                                    J 1 Reply Last reply 8 Feb 2018, 17:14
                                    0
                                    • D devhobby
                                      8 Feb 2018, 17:09

                                      @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                      @devhobby

                                      Is the prediction of what I want to happen... and can't manage to make it happen actually

                                      Ohhhh...! :)

                                      OK, I would expect you've done the right stuff. I believe that's what our code does. I can only think of what I suggested: that the SELECT makes the model read-only, and editing is not allowed.

                                      I shall step aside and you need an expert here to guide you further....

                                      Yes, the custom query is most likely keeping my Table View read-only.

                                      I just want to visually edit the cells...

                                      This is far more complicated than I thought...

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 8 Feb 2018, 17:14 last edited by JonB 2 Aug 2018, 17:41
                                      #26

                                      @devhobby
                                      http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

                                      I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

                                      P.S.
                                      Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

                                      Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

                                      https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

                                      Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

                                      EDIT: You have to loop over every item in your table view to make it individually editable....

                                      D 1 Reply Last reply 8 Feb 2018, 17:37
                                      2
                                      • J JonB
                                        8 Feb 2018, 17:14

                                        @devhobby
                                        http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

                                        I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

                                        P.S.
                                        Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

                                        Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

                                        https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

                                        Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

                                        EDIT: You have to loop over every item in your table view to make it individually editable....

                                        D Offline
                                        D Offline
                                        devhobby
                                        wrote on 8 Feb 2018, 17:37 last edited by
                                        #27

                                        @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                        @devhobby
                                        http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

                                        I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

                                        P.S.
                                        Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

                                        Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

                                        https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

                                        Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

                                        I'd like to change Table View's flag to Qt::ItemIsEditable... but can't find a way to do it

                                        There's no setFlags() method here...

                                        J 1 Reply Last reply 8 Feb 2018, 17:42
                                        0
                                        • D devhobby
                                          8 Feb 2018, 17:37

                                          @JonB said in QSqlRelationalTableModel with multiple Joins?:

                                          @devhobby
                                          http://doc.qt.io/qt-5/qitemdelegate.html#details must be to do with it.

                                          I could easily be wrong(!), but I thought the idea of the model/view would be that if you edit it would save the value back to the model, not "just give you some string". You can doubtless play with the delegate to do something else...

                                          P.S.
                                          Look at http://www.qtcentre.org/threads/38338-Can-t-edit-my-QTableView-cells:

                                          Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.

                                          https://stackoverflow.com/questions/28186118/how-to-make-qtableview-to-enter-the-editing-mode-only-on-double-click:

                                          Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it.

                                          I'd like to change Table View's flag to Qt::ItemIsEditable... but can't find a way to do it

                                          There's no setFlags() method here...

                                          J Offline
                                          J Offline
                                          JonB
                                          wrote on 8 Feb 2018, 17:42 last edited by JonB 2 Aug 2018, 17:49
                                          #28

                                          @devhobby
                                          You have to loop over every item in your table view to make it individually editable (if you're not creating the items yourself, or unless someone suggests a way to cause that to happen as it binds to your model, e.g. https://stackoverflow.com/a/28226056/489865)....

                                          D 1 Reply Last reply 8 Feb 2018, 17:47
                                          1

                                          18/67

                                          8 Feb 2018, 16:44

                                          49 unread
                                          • Login

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