Results 1 to 2 of 2

Thread: calculated columns for QSqlRelationalTableModel

  1. #1
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question calculated columns for QSqlRelationalTableModel

    I'm working on an app for a MySQL db. One of the tables features 3 columns that I'd like to sum up per row and then a subtotal for all rows for those 3 columns.
    I managed to get the column subtotals, but for the row total (for the 3 fields of that particular row), I would need a calculated field.

    After googling, the only reference I could find is this thread:
    http://lists.trolltech.com/qt-intere...ad00142-0.html

    would that be the best way to approach this or is it possible to change the underlying SQL for the QSqlRelationalTableModel?

    cheers,
    -A

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: calculated columns for QSqlRelationalTableModel

    I tried what was suggested in the link, but it doesn't work, i.e. the newly calculated row doesn't show, even though I inserted the new column in my instance of my custom model (based on QSqlRelationalTableModel).

    my data method looks like this:

    Qt Code:
    1. QVariant CustomModel::data(const QModelIndex &index, int role) const
    2. {
    3. QVariant value = QSqlRelationalTableModel::data(index,role);
    4.  
    5. if(role == Qt::TextAlignmentRole && (index.column() == 4 || index.column() ==5 || index.column() == 6))
    6. value = QVariant(Qt::AlignRight | Qt::AlignVCenter);
    7. else if(role == Qt::DisplayRole && index.column() == 7)
    8. {
    9. QModelIndex mi = this->index(index.row(),4,QModelIndex());
    10.  
    11. value = QVariant(mi.data(role)) ;
    12. }
    13. else
    14. value = QSqlRelationalTableModel::data(index, role);
    15.  
    16. return value;
    17. }
    To copy to clipboard, switch view to plain text mode 
    what am I missing?

Similar Threads

  1. Heterogenous columns in QTreeView
    By justinleona in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2009, 23:37
  2. Replies: 8
    Last Post: 14th August 2008, 16:48
  3. Saving/Restoring columns order of QTreeWidget
    By mchara in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 09:43
  4. Spanned Item Spacing on Empty Columns
    By giverson in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2007, 23:10
  5. Replies: 6
    Last Post: 5th March 2006, 22:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.