how to refresh QTableWidget cells, after changing back-ground color

1.3k Views Asked by At

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

There are 1 best solutions below

0
baziorek On

The method worked for me:

QAbstractItemView::reset();

QTableWidget inherits after QAbstractItemView