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. How to choose which columns to display and in which order when using QSqlRelationalTableModel?

How to choose which columns to display and in which order when using QSqlRelationalTableModel?

Scheduled Pinned Locked Moved Solved General and Desktop
sql
8 Posts 3 Posters 429 Views
  • 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.
  • J Offline
    J Offline
    jdent
    wrote on 7 Mar 2024, 15:52 last edited by
    #1

    I have a QSqlRelationalTableModel but there is no way to select which columns to display and in what order...
    If I replace it with a query string then I lose the setRelation() functionality which is very valuable to me
    How can I specify which columns I want to display and still have the setRelation() functionality?

    Thanks!

    J 1 Reply Last reply 7 Mar 2024, 19:04
    0
    • J jdent
      7 Mar 2024, 21:54

      @SGaist There is a protected slot for columnMoved but I don't'see a method moveColumn()
      Can you please orient me more specifically?

      J Offline
      J Offline
      JonB
      wrote on 7 Mar 2024, 22:11 last edited by JonB 3 Jul 2024, 22:11
      #8

      @jdent

      but I don't'see a method moveColumn()

      bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)

      But (and I see @SGaist has just posted) you don't want to move columns around in the model to change the order they are displayed. You do this in the view, the QHeaderView which is the QTableView::horizontalHeader() , by moving its sections.

      1 Reply Last reply
      1
      • J jdent
        7 Mar 2024, 15:52

        I have a QSqlRelationalTableModel but there is no way to select which columns to display and in what order...
        If I replace it with a query string then I lose the setRelation() functionality which is very valuable to me
        How can I specify which columns I want to display and still have the setRelation() functionality?

        Thanks!

        J Offline
        J Offline
        JonB
        wrote on 7 Mar 2024, 19:04 last edited by JonB 3 Jul 2024, 19:06
        #2

        @jdent
        I don't understand. A QSqlRelationalTableModel is a QSqlTableModel just with additional "look up" of column(s) in other table(s) for display and editing purposes.

        It is not about mapping to another table and then being able to pick arbitrary rows or columns there, your own JOINs etc., which I think you might be thinking about.

        Per your other question, again I think you're hoping for too much from the base QSql classes. I came from MS .NET data classes, they offered a lot more if you're looking for DataSet-level stuff,

        J 1 Reply Last reply 7 Mar 2024, 21:46
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Mar 2024, 20:27 last edited by
          #3

          Hi,

          That's the kind of things you do at the QTableView and/or QHeaderView level.

          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
          • J JonB
            7 Mar 2024, 19:04

            @jdent
            I don't understand. A QSqlRelationalTableModel is a QSqlTableModel just with additional "look up" of column(s) in other table(s) for display and editing purposes.

            It is not about mapping to another table and then being able to pick arbitrary rows or columns there, your own JOINs etc., which I think you might be thinking about.

            Per your other question, again I think you're hoping for too much from the base QSql classes. I came from MS .NET data classes, they offered a lot more if you're looking for DataSet-level stuff,

            J Offline
            J Offline
            jdent
            wrote on 7 Mar 2024, 21:46 last edited by
            #4

            @JonB Yes I am expecting much more. One question then: how can I move columns in a QTableView? How can I hide columns in a QTableView?

            S 1 Reply Last reply 7 Mar 2024, 21:48
            0
            • J jdent
              7 Mar 2024, 21:46

              @JonB Yes I am expecting much more. One question then: how can I move columns in a QTableView? How can I hide columns in a QTableView?

              S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 7 Mar 2024, 21:48 last edited by
              #5

              @jdent please read the classes documentation I linked.

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

              J 1 Reply Last reply 7 Mar 2024, 21:54
              0
              • S SGaist
                7 Mar 2024, 21:48

                @jdent please read the classes documentation I linked.

                J Offline
                J Offline
                jdent
                wrote on 7 Mar 2024, 21:54 last edited by
                #6

                @SGaist There is a protected slot for columnMoved but I don't'see a method moveColumn()
                Can you please orient me more specifically?

                S J 2 Replies Last reply 7 Mar 2024, 22:07
                0
                • J jdent
                  7 Mar 2024, 21:54

                  @SGaist There is a protected slot for columnMoved but I don't'see a method moveColumn()
                  Can you please orient me more specifically?

                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 7 Mar 2024, 22:07 last edited by
                  #7

                  @jdent QHeaderView::moveSection

                  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
                  1
                  • J jdent
                    7 Mar 2024, 21:54

                    @SGaist There is a protected slot for columnMoved but I don't'see a method moveColumn()
                    Can you please orient me more specifically?

                    J Offline
                    J Offline
                    JonB
                    wrote on 7 Mar 2024, 22:11 last edited by JonB 3 Jul 2024, 22:11
                    #8

                    @jdent

                    but I don't'see a method moveColumn()

                    bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)

                    But (and I see @SGaist has just posted) you don't want to move columns around in the model to change the order they are displayed. You do this in the view, the QHeaderView which is the QTableView::horizontalHeader() , by moving its sections.

                    1 Reply Last reply
                    1
                    • J jdent has marked this topic as solved on 7 Mar 2024, 22:40

                    8/8

                    7 Mar 2024, 22:11

                    • Login

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