QTableWidget - How to set background-color with widget
-
Hello,
I try to set a background color to my QTableWidget (particular celle or row) with setBackgroundColor.
This function works with QTableWidgetItem but crashes with others items like QCheckBox are contained in the gridIs there any other function to set the color in a cell/row ?
I've already tried *setstylesheet *function, which crashes too...
-
Hi,
Can you share the code you use to setup the background color and widgets ?
-
yes of course :
[...]
tableItem = new QTableWidgetItem("");
tableItem->setFlags(tableItem->flags() & ~(Qt::ItemIsEditable));
//Add Table items here With Default Cell Texts
ui->tableWidget->setItem(y,0,new QTableWidgetItem(""));
ui->tableWidget->setItem(y,1,tableItem);
ui->tableWidget->setItem(y,2,new QTableWidgetItem(""));
ui->tableWidget->setCellWidget(y,3,new QCheckBox(""));
ui->tableWidget->setCellWidget(y,4,new QCheckBox(""));
ui->tableWidget->setCellWidget(y,5,new QCheckBox(""));
[...]The background-color works only for "QTableWidgetItem" cells (without widget)
-
When you set a cell widget you don't see the item underneath (and you don't have any under), you have to set the background on the widget itself.
-
You can try by modifying the palette of the application.
-
You want to modify only that widget and all its children ?
-
Then you can write the style sheet so that it applies to both your QTableWidget and its children widgets