MainWindow
::MainWindow(QWidget *parent
){
this->edit=new QPlainTextEdit(this);
this->setCentralWidget(this->edit);
connect(edit->document(),SIGNAL(contentsChange(int,int,int)),this,SLOT(contentsChange(int,int,int)));
}
void MainWindow
::SetFormat(int position,
int length,
QTextCharFormat &format
) { if (this->edit->document()!=NULL) {
curA.beginEditBlock();
if (curA.hasSelection()) {
curA.mergeCharFormat(format);
curA.clearSelection();
}
curA.endEditBlock();
} else {
qDebug("qplaintextedit->document() is null.");
}
}
void MainWindow::contentsChange(int position,int charsRemoved,int charsAdded) {
if (this->edit->toPlainText().length()>10) {
charFormat.setFontItalic(true);
this->SetFormat(0,3,charFormat);
}
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->edit=new QPlainTextEdit(this);
this->setCentralWidget(this->edit);
connect(edit->document(),SIGNAL(contentsChange(int,int,int)),this,SLOT(contentsChange(int,int,int)));
}
void MainWindow::SetFormat(int position,int length,QTextCharFormat &format) {
if (this->edit->document()!=NULL) {
QTextCursor curA(this->edit->document());
curA.setPosition(position,QTextCursor::MoveAnchor);
curA.setPosition(length,QTextCursor::KeepAnchor);
curA.beginEditBlock();
if (curA.hasSelection()) {
curA.mergeCharFormat(format);
curA.clearSelection();
}
curA.endEditBlock();
} else {
qDebug("qplaintextedit->document() is null.");
}
}
void MainWindow::contentsChange(int position,int charsRemoved,int charsAdded) {
if (this->edit->toPlainText().length()>10) {
QTextCharFormat charFormat;
charFormat.setFontItalic(true);
this->SetFormat(0,3,charFormat);
}
}
To copy to clipboard, switch view to plain text mode
ASSERT: "n" in file ..\..\include\QtGui/private/../../../src/gui/text/qfragmentmap_p.h, line 291
ASSERT: "n" in file ..\..\include\QtGui/private/../../../src/gui/text/qfragmentmap_p.h, line 291
To copy to clipboard, switch view to plain text mode
Bookmarks