标题:怎么设置CellWidget的选中背景色呢?
作者:shixingya
日期:2018-01-08 17:02
内容:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget *wgt =new QWidget();
QVBoxLayout *lout =new QVBoxLayout(wgt);
QLabel *studentNameLabel =new QLabel("cellWidget",nullptr);
studentNameLabel->setAttribute(Qt::WA_TranslucentBackground);
lout->addWidget(studentNameLabel);
QLabel *studentMoberLabel =new QLabel("cellWidget",nullptr);
studentMoberLabel->setAttribute(Qt::WA_TranslucentBackground);
lout->addWidget(studentMoberLabel);
studentMoberLabel->setMinimumWidth(81);
wgt->setLayout(lout);
ui->tableWidget->setCellWidget(0,0,wgt);
}
#1 [shixingya 01-08 17:42]
//改变CellWidget颜色
void GradeLiftWgt::on_tableWidget_cellPressed(int row, int column)
{
for(int i=0; itableWidget->columnCount(); i++)
{
QWidget *wgt =ui->tableWidget->cellWidget(row,i);
if(wgt)
{
wgt->setStyleSheet("background-color:lightblue;");
}
}
}
结帖