- //设置选中的文本的颜色
- QColor color = QColorDialog::getColor(Qt::black, this, "Select Color", QColorDialog::DontUseNativeDialog);
- if(color.isValid())
- {
- ui->doc->setTextColor(color);
- }
- //设置选中整个编辑区域的背景色
- QColor color = QColorDialog::getColor(Qt::white, this, "Select Color", QColorDialog::DontUseNativeDialog);
- if(color.isValid())
- {
- QString tmp("QTextEdit {background-color:");
- tmp += color.name();
- tmp += QString(";}");
- ui->doc->setStyleSheet(tmp);
- ui->doc->setTextBackgroundColor(color);
- }
- //设置选中的文本的背景色
- QColor color = QColorDialog::getColor(Qt::white, this, "Select Color", QColorDialog::DontUseNativeDialog);
- if(color.isValid())
- {
- ui->doc->setTextBackgroundColor(color);
- }
- //设置选中的文本的字体
- bool ok;
- QFont font = QFontDialog::getFont(&ok, this);
- if (ok)
- {
- QTextCursor cur = ui->doc->textCursor();
- QString sltStr = cur.selectedText();
- ui->doc->cut();
- QTextCharFormat fmtText;
- fmtText.setFont(font);
- cur.insertText(sltStr,fmtText);
- }
转载于:https://blog.51cto.com/hakuyo/1125782