c++ - Qt TableWidget - The image that appears when you click the cell -
i use qtablewidget 2 columns. first column display images. second column display text. i'm calling qbrush::settexture
on first column, not seticon
function.
i want first column images change when click on cell there problem image appears when click cell.
this image expect:
this image get:
here code
.h file
class kcbackgrounddelegate : public qstyleditemdelegate { public: explicit kcbackgrounddelegate(qobject *parent = 0) : qstyleditemdelegate(parent) { } void paint(qpainter *painter, const qstyleoptionviewitem &option, const qmodelindex &index) const { qvariant background = index.data(qt::backgroundrole); if (background.canconvert<qbrush>()) painter->fillrect(option.rect, background.value<qbrush>()); qstyleditemdelegate::paint(painter, option, index); if(option.state & qstyle::state_mouseover) { if(index.column() == 0 ) { painter->save(); painter->fillrect(option.rect,qbrush(qpixmap(":/resources/img/system/setting_aircraft_on_bt.png"))); painter->restore(); } } if(option.state & qstyle::state_selected) { if(index.column() == 0) { painter->save(); painter->fillrect(option.rect,qbrush(qpixmap(":/resources/img/system/setting_aircraft_click_bt.png"))); painter->restore(); } } } };
.cpp file
ui->tw_aircraft_type->setitemdelegateforcolumn(0,new kcbackgrounddelegate(this)); ui->tw_aircraft_type->setmousetracking(true); ui->tw_aircraft_type->viewport()->setmousetracking(true); ui->tw_aircraft_type->installeventfilter(this); ui->tw_aircraft_type->viewport()->installeventfilter(this);
it seems there problem delegate don't know how fix it. please me.