Results 1 to 6 of 6

Thread: HightLight particular Row in QStandardItemModel QTableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    41
    Thanks
    12

    Default HightLight particular Row in QStandardItemModel QTableView

    Hello every one i am working a data representing software where i show some pressure type data in a QTableView.. I have written a function to tell if the pressure data has exceeded the limits which is set by the user in the GUI. But i wanted to highlight the QTableView Cell which has crossed the limit. I could not find out how to hightlight. Can some one pls help me out with this problem i don't know how to hightlight the a particular row data in table view.. The Data in the Table View is refreshed every 3 seconds.

    Qt Code:
    1. for(int kt=0; kt<pressuredata.count(); kt++)
    2. {
    3. if((maxval < pressuredata.at(kt).toFloat())||(minval > pressuredata.at(kt).toFloat()))
    4. {
    5. qLed2_2->setColor(Qt::red);
    6. label_9->setText("Pressure Limit Excceded");
    7. setlimiflag =1;
    8. limitposi = kt;
    9. break;
    10. }
    11.  
    12. else
    13. setlimiflag =0;
    To copy to clipboard, switch view to plain text mode 

    I am thinking the position kt can be used to highlight the particular row in the table view which is out of limits.. Give me some suggestions on how i could go about this. and how should i highlight a row in QTableView. ??

    Regards

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: HightLight particular Row in QStandardItemModel QTableView

    You can set background color for all columns in the row u want.
    Other way is to use a delegate. In delegate you can check for a condition and then paint accordingly

  3. The following user says thank you to aamer4yu for this useful post:

    rex (19th March 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: HightLight particular Row in QStandardItemModel QTableView

    Currently, I see two ways of doing this :

    try setting the Qt::BackgroundRole of the designated cell in your model.

    Otherwise, you could try defining your own delegate (QStyledItemDelegate) and overriding the
    Qt Code:
    1. QStyledItemDelegate::paint
    To copy to clipboard, switch view to plain text mode 
    method to highlight your cell :

    Qt Code:
    1. void MyDelegate::::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
    2. {
    3. int value = index.model()->data().toInt();
    4. if (value > max)
    5. {
    6. painter->fillRect(option.rect, Qt::red);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    (didn't try the code).

  5. The following user says thank you to Octal for this useful post:

    rex (19th March 2011)

Similar Threads

  1. QStandardItemModel / QTableView sorting issue
    By AlphaWolfXV in forum Qt Programming
    Replies: 2
    Last Post: 31st August 2010, 05:42
  2. Replies: 1
    Last Post: 30th August 2010, 21:24
  3. Hightlight not lost
    By wirasto in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2010, 13:16
  4. qtableview QStandardItemModel read only
    By JeanC in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2008, 16:42
  5. Extract QStandardItemModel from QTableView
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2008, 08:34

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.