加粗
void TextEdit::SetFontBoldButton()
{
QTextCharFormat tcf;
tcf.setFontWeight(BoldButton->isChecked() ? QFont::Bold : QFont::Normal);
ui->textEdit->mergeCurrentCharFormat(tcf);
}
预设值 QFont::Light(25) QFont::Normal(50) QFont::DemiBold(63) QFont::Bold(75) QFont::Black(87)
倾斜
void TextEdit::SetFontItalicButton()
{
QTextCharFormat tcf;
tcf.setFontItalic(ItalicButton->isChecked());
ui->textEdit->mergeCurrentCharFormat(tcf);
}
下划线
void TextEdit::SetFontUnderButton()
{
QTextCharFormat tcf;
tcf.setFontUnderline(UnderButton->isChecked());
ui->textEdit->mergeCurrentCharFormat(tcf);
}
颜色
void TextEdit::SetFontColorButton()
{
QColor Color = QColorDialog::getColor(Qt::black, this);
if(Color.isValid())
{
QTextCharFormat tcf;
tcf.setForeground(Color);
ui->textEdit->mergeCurrentCharFormat(tcf);
}
}