QTableWidget - How to set background-color with widget
-
wrote on 18 Sept 2015, 16:30 last edited by
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 ?
-
wrote on 22 Sept 2015, 14:52 last edited by
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.
-
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
-
Then you can write the style sheet so that it applies to both your QTableWidget and its children widgets
-
It seems to work on QTableWidget but not on children widgets when I set the style sheet
wrote on 9 Oct 2015, 16:16 last edited byI have resolved my problem with :
ui->tableWidget->item(i,j)->setBackground(Qt::gray);