if(QDialog::Accepted == colorDialog->exec()) ui->textEdit->setTextColor(colorDialog->currentColor());;修改textEdit背景色
修改textEdit的背景色可以使用以下代码:
if(QDialog::Accepted == colorDialog->exec())
ui->textEdit->setStyleSheet("background-color:" + colorDialog->currentColor().name() + ";");
这里使用了QColor的name()函数来获取颜色的字符串表示,然后将其添加到样式表中。注意,这里使用了双引号来包裹样式表,因为颜色值可能包含空格,使用单引号可能会导致编译错误。
原文地址: https://www.cveoy.top/t/topic/uUa 著作权归作者所有。请勿转载和采集!