加粗
cpp
void MainWindow::on_checkbox_Bold_stateChanged(int arg1)
{
ui->textEdit->selectAll();
QTextCharFormat fmt = ui->textEdit->currentCharFormat();
if(arg1 == Qt::Checked)
{
fmt.setFontWeight(QFont::Bold);
}else
{
fmt.setFontWeight(QFont::Normal);
}
ui->textEdit->mergeCurrentCharFormat(fmt);
// QString str = ui->textEdit->toPlainText();
// ui->textEdit->setText(str);
ui->textEdit->append("追加文字");
}
下划线
cpp
void MainWindow::on_checkbox_Unline_stateChanged(int arg1)
{
QTextCharFormat fmt = ui->textEdit->currentCharFormat();
if(arg1 == Qt::Checked)
{
fmt.setFontUnderline(true);
}else
{
fmt.setFontUnderline(false);
}
ui->textEdit->mergeCurrentCharFormat(fmt);
QString str = ui->textEdit->toPlainText();
ui->textEdit->setText(str);
ui->textEdit->append("追加文字");
}
斜体
cpp
void MainWindow::on_checkbox_Italic_stateChanged(int arg1)
{
QTextCharFormat fmt = ui->textEdit->currentCharFormat();
if(arg1 == Qt::Checked)
{
fmt.setFontItalic(true);
}else
{
fmt.setFontItalic(false);
}
ui->textEdit->mergeCurrentCharFormat(fmt);
QString str = ui->textEdit->toPlainText();
ui->textEdit->setText(str);
ui->textEdit->append("追加文字");
}
字体大小
cpp
void MainWindow::on_spinSize_valueChanged(int arg1)
{
QTextCharFormat fmt = ui->textEdit->currentCharFormat();
fmt.setFontPointSize(arg1);
ui->textEdit->mergeCurrentCharFormat(fmt);
QString str = ui->textEdit->toPlainText();
ui->textEdit->setText(str);
ui->textEdit->append("追加文字");
}
字体设置
cpp
void MainWindow::on_fontComboBox_currentFontChanged(const QFont &f)
{
QTextCharFormat fmt = ui->textEdit->currentCharFormat();
fmt.setFont(f);
ui->textEdit->mergeCurrentCharFormat(fmt);
QString str = ui->textEdit->toPlainText();
ui->textEdit->setText(str);
ui->textEdit->append("追加文字");
}