add of setbold, setItalic, setUnderlined and setFontColor functions
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QLineEdit>
|
||||
#include <QTimer>
|
||||
#include <QTextEdit>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@@ -212,3 +213,91 @@ void MainWindow::on_actionEditCut_triggered()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setBold(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
QFont font = textEdit->currentFont();
|
||||
font.setBold(!font.bold());
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionBold_triggered()
|
||||
{
|
||||
this->setBold();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::setItalic(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
QFont font = textEdit->currentFont();
|
||||
font.setItalic(!font.italic());
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionItalic_triggered()
|
||||
{
|
||||
this->setItalic();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setUnderline(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
QFont font = textEdit->currentFont();
|
||||
font.setUnderline(!font.underline());
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionUnderline_triggered()
|
||||
{
|
||||
this->setUnderline();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::setColor(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
format.setForeground(QBrush(QColor(255,0,0)));
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::on_actionColor_triggered()
|
||||
{
|
||||
this->setColor();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user