Results 1 to 9 of 9

Thread: Column Colour

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Column Colour

    Hi,

    How can I show a readonly column in Gray colour in a QTable.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Column Colour

    You have to subclass QTableItem and reimplement its paint() routine. And of course use this subclass instead of QTableItem if you need such behaviour.

  3. #3
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Column Colour

    Thanks

    Qt Code:
    1. void MyTableItem::paint (QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected)
    2. {
    3. QColorGroup g(cg);
    4. g.setColor( QColorGroup::Background, Qt::red );
    5. QTableItem::paint (p, cg, cr, selected);
    6. }
    To copy to clipboard, switch view to plain text mode 

    but its not working

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Column Colour

    How did you use this code?

  5. #5
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Column Colour

    should I use something else???

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Column Colour

    Use "Base" instead of "Background".

    BTW. There is an error in your code. You are calling paint() with cg instead of g.

  7. #7
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Column Colour

    first i use Base but its also not working, then I use Background which is also not working.

    Is there any other way to do so???

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Column Colour

    Did you correct that paint() call?

    You have:
    Qt Code:
    1. QTableItem::paint (p, cg, cr, selected);
    To copy to clipboard, switch view to plain text mode 
    and it should be:
    Qt Code:
    1. QTableItem::paint (p, g, cr, selected);
    To copy to clipboard, switch view to plain text mode 

    This works for me:

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qtable.h>
    3.  
    4. class MyTableItem : public QTableItem {
    5. public:
    6. MyTableItem(QTable *table) : QTableItem(table, QTableItem::OnTyping){}
    7. void paint(QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected){
    8. QColorGroup g(cg);
    9. g.setColor(QColorGroup::Base, Qt::red);
    10. QTableItem::paint(p, g, cr, selected);
    11. }
    12.  
    13. };
    14.  
    15. int main(int argc, char **argv){
    16. QApplication app(argc, argv);
    17. QTable tab(1,1);
    18. tab.setItem(0,0, new MyTableItem(&tab));
    19. app.setMainWidget(&tab);
    20. tab.show();
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to wysota for this useful post:

    sumsin (15th June 2006)

  10. #9
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Column Colour

    Problem solved.
    You are right. I should use g instead of cg.
    Thanks.

Similar Threads

  1. Setting Delegates per Column
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2006, 21:39
  2. QTable column stretchable with minimum Width
    By sunil.thaha in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2006, 13:17
  3. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  4. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 15:51

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.