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. TableView, SQLite, QSqlRelationalTableModel
Forum Updated to NodeBB v4.3 + New Features

TableView, SQLite, QSqlRelationalTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 230 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.
  • C Offline
    C Offline
    Colorado_Al
    wrote on last edited by
    #1

    I'm new to QT but started with Borland C.

    I have a desktop app that makes use of TableViews and a database with lots of relations.
    My question is how to assign a certain field to a certain column.. ie changing the display order.

    Here's a code snippit:

    // QSqlRelationalTableModel ////////////////////////////////////////////////////////////////////////////////////////////////
    QSqlRelationalTableModel *model = new QSqlRelationalTableModel;
    model->setJoinMode(QSqlRelationalTableModel::LeftJoin);
    model->setTable("tblSales");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);

    model->setRelation(4,   QSqlRelation("tblJewelryPiece", "JewelryPieceID", "Category"));// set Relation
    model->setRelation(5,   QSqlRelation("tblJewelryPiece", "JewelryPieceID", "PieceName"));
    
    model->setHeaderData(0, Qt::Horizontal, tr("Invoice #"));                               // set Header Data
    model->setHeaderData(2, Qt::Horizontal, tr("Date"));
    model->setHeaderData(3, Qt::Horizontal, tr("Qty"));
    model->setHeaderData(4, Qt::Horizontal, tr("Category"));
    model->setHeaderData(6, Qt::Horizontal, tr("Jewelry Piece"));
    model->setHeaderData(7, Qt::Horizontal, tr("Price"));
    
    model->setFilter("CustomerID=" + val);                            // set filter to current customer
    
    model->select();                                                                        // select
    ui->tv_Sales->setModel(model);
     ui->tv_Sales->resizeColumnsToContents();
     ui->tv_Sales->show();
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I would go with QHeaderView::moveSection()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Colorado_Al
        wrote on last edited by
        #3

        Thanks, will give that a shot... ( still learning the classes ).

        Thanks!

        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