class MyItem : public QTableItem { public: MyItem(QTable *table,EditType et,const QString& text) : QTableItem(table,et,text) { m_crBkg = Qt::white; m_crTxt = Qt::black; m_HorzAlign = Qt::AlignRight; m_VertAlign = Qt::AlignVCenter; } void paint(QPainter* p,const QColorGroup& cg,const QRect& cr,bool selected) { int w = cr.width(); int h = cr.height(); if (selected && colSpan() == 1 ) { p->fillRect( 0 , 0 , w , h , cg.brush( QColorGroup::Highlight ) ); p->setPen( cg.highlightedText() ); } else { p->fillRect( 0 , 0 , w , h , m_crBkg ); p->setPen( m_crTxt ); } p->drawText( 2 , 0 , w - 4 , h , wordWrap() ? ( m_HorzAlign|m_VertAlign | WordBreak) : m_HorzAlign|m_VertAlign , text() ); } QColor m_crBkg; QColor m_crTxt; Qt::AlignmentFlags m_HorzAlign; Qt::AlignmentFlags m_VertAlign; };