64,648
社区成员
发帖
与我相关
我的任务
分享
void Text::font()
{
QTextCharFormat fmt;
QFont font;
fmt.setFont(font = QFontDialog::getFont(0, font));
QTextCursor cursor = editor->textCursor();
if (cursor.hasSelection())
{
cursor.mergeCharFormat(fmt);
}
else
{
editor->setFont(font);
}
QString str = editor->toPlainText();
//我用的是Qt 5.7,只有toPlainText()这个函数可以用来获取文本
editor->clear();
editor->setText(str);
}