Results 1 to 3 of 3

Thread: Coloring a QTableview column

  1. #1
    Join Date
    Apr 2008
    Location
    Fons Outre-Gardons
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Coloring a QTableview column

    Hello,

    So far I use the following way to color the colum of a tableview :
    Qt Code:
    1. // Color the colum
    2. for (int i = FirstLine; i < Max_Number_of_Lines; i++)
    3. InputDataModel->setData(InputDataModel->index(i, SelectedColumn), SelectedVariableColor, Qt::BackgroundRole);
    To copy to clipboard, switch view to plain text mode 

    It works but it is very slow when Max_Number_of_Lines is greater than 2000. Then I have to wait 2 or 3s before it's colored.

    Would you know if there is a faster (and more clever) way to proceed ?

    Thanks in advance

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Coloring a QTableview column

    1. create your own item delegete
    2. derive it from QStyledItemDelegate
    3. override the paint function
    4. use the option variable to get the rect and fill it with ur color(read about it from Qt Assistant first)
    5. set this delegate on ur choice of column using setItemDelegateForColumn

  3. #3
    Join Date
    Apr 2008
    Location
    Fons Outre-Gardons
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Coloring a QTableview column

    Ok thanks.
    I will follow your advises.

Similar Threads

  1. Replies: 2
    Last Post: 21st January 2011, 17:12
  2. QTableView column trouble
    By nategoofs in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2009, 20:14
  3. QTreeView Fixed column & QTableView
    By jpujolf in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2008, 09:35
  4. QTableView + QSqlQueryModel column alignment
    By frido in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2008, 06:12
  5. QTableView without the first counter column?
    By pmaktieh.sirhc in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2007, 22:03

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.