Hi,
How can I show a readonly column in Gray colour in a QTable.
Printable View
Hi,
How can I show a readonly column in Gray colour in a QTable.
You have to subclass QTableItem and reimplement its paint() routine. And of course use this subclass instead of QTableItem if you need such behaviour.
How did you use this code?
should I use something else???
Use "Base" instead of "Background".
BTW. There is an error in your code. You are calling paint() with cg instead of g.
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???
Did you correct that paint() call?
You have:
and it should be:Code:
QTableItem::paint (p, cg, cr, selected);
Code:
QTableItem::paint (p, g, cr, selected);
This works for me:
Code:
#include <qapplication.h> #include <qtable.h> class MyTableItem : public QTableItem { public: MyTableItem(QTable *table) : QTableItem(table, QTableItem::OnTyping){} QColorGroup g(cg); g.setColor(QColorGroup::Base, Qt::red); QTableItem::paint(p, g, cr, selected); } }; int main(int argc, char **argv){ QTable tab(1,1); tab.setItem(0,0, new MyTableItem(&tab)); app.setMainWidget(&tab); tab.show(); return app.exec(); }
Problem solved.
You are right. I should use g instead of cg.
Thanks.