qtextcursor

Qt ignores CSS in QTextDocument

寵の児 提交于 2020-01-11 09:51:39
问题 Here is a small snippet of my code, I don't know why but Qt is ignoring the css. QTextDocument *mTextDocument = new QTextDocument(0); QTextEdit *textEdit = new QTextEdit(0); mTextDocument->setDefaultStyleSheet(QString::fromUtf8("body{background-color: rgb(0,111,200);}")); QTextCursor *_cursor = new QTextCursor(mTextDocument); textEdit->setDocument(mTextDocument); _cursor->insertBlock(); _cursor->insertHtml("<html><body><p>Hello world</p></body></html>"); textEdit->show(); I'm using Qt 4.8.

Selecting a piece of text using QTextCursor

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 03:01:35
问题 Having problems with selecting pieces of text using the Qt framework. For example if i have this document : "No time for rest". And i want to select "ime for r" and delete this piece of text from the document, how should i do it using QTextCursor? Here is my code: QTextCursor *cursor = new QTextCursor(ui->plainTextEdit->document()); cursor->setPosition(StartPos,QTextCursor::MoveAnchor); cursor->setPosition(EndPos,QTextCursor::KeepAnchor); cursor->select(QTextCursor::LineUnderCursor); cursor-

QTextCursor and beginEditBlock

筅森魡賤 提交于 2019-12-11 02:16:52
问题 I have some text in QPlainTextEdit, where every line starts with 10 spaces: line1 line2 line3 line4 Then, I select few lines and in a loop I want to remove first two spaces from all the selected lines: cursor.beginEditBlock(); for (QTextBlock block = startBlock; block != endBlock; block = block.next()) { cursor.setPosition(block.position()); cursor.setPosition(block.position() + 2, QTextCursor::KeepAnchor); cursor.removeSelectedText(); } cursor.endEditBlock(); The problem is that the code

Qt ignores CSS in QTextDocument

旧时模样 提交于 2019-12-01 21:43:37
Here is a small snippet of my code, I don't know why but Qt is ignoring the css. QTextDocument *mTextDocument = new QTextDocument(0); QTextEdit *textEdit = new QTextEdit(0); mTextDocument->setDefaultStyleSheet(QString::fromUtf8("body{background-color: rgb(0,111,200);}")); QTextCursor *_cursor = new QTextCursor(mTextDocument); textEdit->setDocument(mTextDocument); _cursor->insertBlock(); _cursor->insertHtml("<html><body><p>Hello world</p></body></html>"); textEdit->show(); I'm using Qt 4.8. Your document already has html and body tags, so they are simply ignored when they are found in