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