问题
I have a matrix created by QTableWidget, I have multiple threads that changing the colors of the cells, I want to see the coloring changing immediately after setting the color. what I have now is that only after finishing all cells coloring I see the whole cells colors changed as once. I have a good delay between the coloring, so it's not that the threads are filling the cells so fast.
every thread calls the function
fillInCell(x,y,val,myThreadIdx);
void ResultMatrix::fillInCell(int i, int j, int val, int color )
{
QTableWidgetItem* item = new QTableWidgetItem();
item->setText(QString::number(val));
colorCell(color,item);
ui->matrixResult->setItem(i,j,item);
}
and colorCell is the function that color cells
void ResultMatrix::colorCell(int threadNum, QTableWidgetItem* item)
{
switch (threadNum)
{
case 0:{
QColor cellColor(255, 0, 0 );
item->setBackgroundColor(cellColor);
return;}
case 1:{
.....
回答1:
The method worked for me:
QAbstractItemView::reset();
QTableWidget inherits after QAbstractItemView
来源:https://stackoverflow.com/questions/21073841/how-to-refresh-qtablewidget-cells-after-changing-back-ground-color