View Full Version : Column Colour
sumsin
15th June 2006, 07:30
Hi,
How can I show a readonly column in Gray colour in a QTable.
wysota
15th June 2006, 07:46
You have to subclass QTableItem and reimplement its paint() routine. And of course use this subclass instead of QTableItem if you need such behaviour.
sumsin
15th June 2006, 09:48
Thanks
void MyTableItem::paint (QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected)
{
QColorGroup g(cg);
g.setColor( QColorGroup::Background, Qt::red );
QTableItem::paint (p, cg, cr, selected);
}
but its not working
wysota
15th June 2006, 10:06
How did you use this code?
sumsin
15th June 2006, 10:16
should I use something else???
wysota
15th June 2006, 10:22
Use "Base" instead of "Background".
BTW. There is an error in your code. You are calling paint() with cg instead of g.
sumsin
15th June 2006, 10:25
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???
wysota
15th June 2006, 10:34
Did you correct that paint() call?
You have:
QTableItem::paint (p, cg, cr, selected);
and it should be:
QTableItem::paint (p, g, cr, selected);
This works for me:
#include <qapplication.h>
#include <qtable.h>
class MyTableItem : public QTableItem {
public:
MyTableItem(QTable *table) : QTableItem(table, QTableItem::OnTyping){}
void paint(QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected){
QColorGroup g(cg);
g.setColor(QColorGroup::Base, Qt::red);
QTableItem::paint(p, g, cr, selected);
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
QTable tab(1,1);
tab.setItem(0,0, new MyTableItem(&tab));
app.setMainWidget(&tab);
tab.show();
return app.exec();
}
sumsin
15th June 2006, 10:38
Problem solved.
You are right. I should use g instead of cg.
Thanks.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.