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 430 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 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!

    JonBJ 1 Reply Last reply
    0
    • J jdent

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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #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

        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!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          • JonBJ JonB

            @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 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?

            SGaistS 1 Reply Last reply
            0
            • J jdent

              @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?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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
              0
              • SGaistS SGaist

                @jdent please read the classes documentation I linked.

                J Offline
                J Offline
                jdent
                wrote on 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?

                SGaistS JonBJ 2 Replies Last reply
                0
                • J jdent

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

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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

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

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #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

                    • Login

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