Results 1 to 5 of 5

Thread: Change column data based on data from another column in QTableView?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change column data based on data from another column in QTableView?

    Well, index.column() can obviously not be 8 and 9 at the same time, so first checking for 8 and the checking for 9 will always fail.

    Just imagine what the view will do when it wants to get the value of column 9 in, lets say the first row.
    It will call data() with an index that contains row=0 and column=9, right?

    So checking for 8 is not going to help you in any way, right?

    So you now have the value for row 0, column 9. You want to return that value or a changed value depending on the value in column 8.
    How do you get the value of column 8, same row?

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    adutzu89 (27th February 2014)

  3. #2
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Change column data based on data from another column in QTableView?

    Thank you for your guiding. I finally solved with the following:
    Qt Code:
    1. QVariant ModelLProd::data(const QModelIndex &index, int role) const
    2. {
    3. QVariant value = QSqlQueryModel::data(index, role);
    4. if (value.isValid() && role == Qt::DisplayRole && index.column() == 9) {
    5. int rand=index.row();
    6. int val=index.sibling(rand,8).data().toInt();
    7. if(val==99){
    8. return value.toString().replace(value.toString(),"0.00");
    9. }
    10. }
    11. return value;
    12. }
    To copy to clipboard, switch view to plain text mode 

    I was looking at the issue the wrong way.

Similar Threads

  1. Get data from QTableView sorted by column
    By qks1 in forum Qt Programming
    Replies: 0
    Last Post: 26th June 2013, 09:27
  2. How to get all column data of a QTableView
    By npascual in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2012, 09:05
  3. Replies: 4
    Last Post: 21st August 2011, 20:38
  4. Replies: 2
    Last Post: 5th September 2010, 14:06
  5. How to change the order of QTableView Column ?
    By Kode.Cooper in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2010, 08:55

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
  •  
Qt is a trademark of The Qt Company.