…
connect(mainTextEdit, SIGNAL(cursorPositionChanged( int , int )), this, SLOT(toggleIfStyle(int, int)) );
…
// then in the toggleIfStyle(int,int) method we have:
void class::toggleIfStyle(int a, int b)
{
QString textParagragh
(mainTextEdit
->text
(a
));
// the text of the current paragraph
mainTextEdit->insertAt(â€<p align=justify>â€, a, 0); // QTextEdit reads HTML tags, so we enter the align=justify tag
mainTextEdit->insertAt(â€</p>â€, a, mainTextEdit->paragraphLength(a)); // close the tag
mainTextEdit->setText(mainTextEdit->text()); // the text has to be re-displayed
}
QTextEdit *mainTextEdit=new QTextEdit(this); // the object where the text is displayed
…
connect(mainTextEdit, SIGNAL(cursorPositionChanged( int , int )), this, SLOT(toggleIfStyle(int, int)) );
…
// then in the toggleIfStyle(int,int) method we have:
void class::toggleIfStyle(int a, int b)
{
QString textParagragh(mainTextEdit->text(a)); // the text of the current paragraph
mainTextEdit->insertAt(â€<p align=justify>â€, a, 0); // QTextEdit reads HTML tags, so we enter the align=justify tag
mainTextEdit->insertAt(â€</p>â€, a, mainTextEdit->paragraphLength(a)); // close the tag
mainTextEdit->setText(mainTextEdit->text()); // the text has to be re-displayed
}
To copy to clipboard, switch view to plain text mode
Bookmarks