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. Changing field order in QSqlTableModel
Qt 6.11 is out! See what's new in the release blog

Changing field order in QSqlTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.6k 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have a QSqlTableModel which displays the fields of a db in a tableWiew. I want to display the fields in a different order in the tableView than the fields are listed in the db table. How can I do that?

    Currently I have the following to display the data:

    
      QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE");
      db.setDatabaseName ("C:/Programming/Projects/Folkfriends_bzr/trunk/db.db");
      if(!db.open ())
        QMessageBox::information (this, "Error", "Couldn't open database.");
    
    
      QSqlTableModel* fixModel = new QSqlTableModel(this);
      fixModel->setTable ("Items");
      fixModel->setEditStrategy (QSqlTableModel::OnFieldChange);
      fixModel->setSort (1, Qt::DescendingOrder);
      fixModel->select ();
    
      ui->tableView_Fix->setModel (fixModel);
    

    Thank you for your help.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      Did u get a chance to look at this old post ?
      https://forum.qt.io/topic/10842/specify-column-ordering-in-qsqltablemodel-was-problem-moving-columns-of-a-qtableview/1

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      G 1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        KRearrangeColumnsProxyModel

        "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

        1 Reply Last reply
        1
        • dheerendraD dheerendra

          Did u get a chance to look at this old post ?
          https://forum.qt.io/topic/10842/specify-column-ordering-in-qsqltablemodel-was-problem-moving-columns-of-a-qtableview/1

          G Offline
          G Offline
          gabor53
          wrote on last edited by
          #4

          @dheerendra
          Yes, but it moves the column header not the actual column. I want to display the columns in a diferent order than they are in the db.

          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