Results 1 to 4 of 4

Thread: cant read data from my model of QIdentityProxyModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cant read data from my model of QIdentityProxyModel

    I modified the code, now it paints red the values i want but i cant change the font because i cant feth the value:

    Qt Code:
    1. QVariant MyModelView::data(const QModelIndex &proxyIndex, int role) const{
    2. if (role == Qt::BackgroundRole && proxyIndex.column()==1){
    3. int value= proxyIndex.model()->data(proxyIndex.model()->index(proxyIndex.row(),1),Qt::DisplayRole).toInt();
    4. if (value < 6){
    5. //proxyIndex.model()->setData(proxyIndex.model()->index(proxyIndex.row(),0), QFont("Courier", 8, QFont::Bold, true), Qt::FontRole);
    6. return QBrush(Qt::red);
    7. }
    8. }
    9. /*if (role == Qt::FontRole && proxyIndex.column()==0){
    10.   int value= proxyIndex.model()->data(proxyIndex.model()->index(proxyIndex.row(),1),Qt::DisplayRole).toInt();
    11.   if (value < 6){
    12.   return QFont("Courier", 8, QFont::Bold, true);
    13.   }
    14.   }*/
    15. return QIdentityProxyModel::data(proxyIndex, role);
    16. }
    To copy to clipboard, switch view to plain text mode 

    (I want to make the commented "if" to work ->when executed it throws segmentation faul)

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: cant read data from my model of QIdentityProxyModel

    try this
    Qt Code:
    1. QVariant data(const QModelIndex & proxyIndex, int role) const
    2. {
    3. if((role == Qt::BackgroundRole) && (proxyIndex.column() == 1))
    4. {
    5. int value = QIdentityProxyModel::data(index(proxyIndex.row(), 1), Qt::DisplayRole).toInt();
    6. if(value < 6)
    7. return QBrush(Qt::red);
    8. }
    9.  
    10. if((role == Qt::FontRole) && (proxyIndex.column() == 0))
    11. {
    12. int value = QIdentityProxyModel::data(index(proxyIndex.row(), 1), Qt::DisplayRole).toInt();
    13. if(value < 6)
    14. return QFont("Courier", 8, QFont::Bold, true);
    15. }
    16.  
    17. return QIdentityProxyModel::data(proxyIndex, role);
    18. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following 2 users say thank you to Santosh Reddy for this useful post:

    code.yash (25th July 2014), KillGabio (12th July 2013)

  4. #3
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cant read data from my model of QIdentityProxyModel

    If you were from Argentina, i d be yelling: "GROSOOOOO"

Similar Threads

  1. read data from website
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 4
    Last Post: 27th June 2013, 11:32
  2. Replies: 9
    Last Post: 14th February 2013, 19:39
  3. how to use QIdentityProxyModel?
    By ecanela in forum Qt Programming
    Replies: 4
    Last Post: 3rd August 2012, 20:29
  4. Replies: 1
    Last Post: 24th February 2011, 05:54
  5. can`t read a binary data!
    By blm in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 16:56

Tags for this Thread

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.