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

天大地大妈咪最大 提交于 2020-01-02 18:52:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!