Hi,
How can I show a readonly column in Gray colour in a QTable.
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.
Thanks
Qt Code:
{ QColorGroup g(cg); g.setColor( QColorGroup::Background, Qt::red ); QTableItem::paint (p, cg, cr, selected); }To copy to clipboard, switch view to plain text mode
but its not working
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:Qt Code:
QTableItem::paint (p, cg, cr, selected);To copy to clipboard, switch view to plain text mode
Qt Code:
QTableItem::paint (p, g, cr, selected);To copy to clipboard, switch view to plain text mode
This works for me:
Qt 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(); }To copy to clipboard, switch view to plain text mode
sumsin (15th June 2006)
Problem solved.
You are right. I should use g instead of cg.
Thanks.
Bookmarks