T
T
theSever2018-03-23 23:10:54
Qt
theSever, 2018-03-23 23:10:54

Qt C++ QTableWidget how to set row color?

Hello, I am unloading a row from the database into a table:

// Обновить таблицу
void MainWindow::table_now()
{
    // Очистить таблицу
    ui->tableWidget->clearContents();
    ui->tableWidget->setRowCount(0);
 
    QString dbzap = "select name,reiting,dat,comment from `Default`";
 
    // Вывод в таблицу
    QSqlQuery query;
    query.exec(dbzap);
    while (query.next())
    {
        ui->tableWidget->insertRow(ui->tableWidget->rowCount());
        for (int i=0; i<4; i++){
            QTableWidgetItem * item = new QTableWidgetItem(query.value(i).toString());
            ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,i,item);
        }
    }
}

Also in the table there is a column "color" in which either the field is empty or the color code is stored, which must be assigned to the line.
How to do the unloading into a table with a color assigned to a row if it is specified?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question