QPlainTextEdit ignores most of the text block formats
up vote
1
down vote
favorite
I wanted to increase spacing between paragraphs (text blocks) in QPlainTextEdit, to no avail. After experimenting I found that though some format properties (e.g., background color) take effect, others (e.g., margins) are ignored.
I found this bug report, but it mentions only QTextBlockFormat::lineHeight()
. In my case, almost all methods of QTextBlockFormat::*
are ignored. A minimal example:
#include <QtWidgets>
int main(int argc, char *argv) {
QApplication a(argc, argv);
QPlainTextEdit te;
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(600);
fmt.setIndent(20);
fmt.setTopMargin(600);
fmt.setLeftMargin(40);
cursor.setBlockFormat(fmt);
te.show();
return a.exec();
}
Except fmt.setBackground(QColor(Qt::yellow))
, others are all ignored. Using Qt 5.10.
c++ qt qt5 qplaintextedit qtextcursor
add a comment |
up vote
1
down vote
favorite
I wanted to increase spacing between paragraphs (text blocks) in QPlainTextEdit, to no avail. After experimenting I found that though some format properties (e.g., background color) take effect, others (e.g., margins) are ignored.
I found this bug report, but it mentions only QTextBlockFormat::lineHeight()
. In my case, almost all methods of QTextBlockFormat::*
are ignored. A minimal example:
#include <QtWidgets>
int main(int argc, char *argv) {
QApplication a(argc, argv);
QPlainTextEdit te;
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(600);
fmt.setIndent(20);
fmt.setTopMargin(600);
fmt.setLeftMargin(40);
cursor.setBlockFormat(fmt);
te.show();
return a.exec();
}
Except fmt.setBackground(QColor(Qt::yellow))
, others are all ignored. Using Qt 5.10.
c++ qt qt5 qplaintextedit qtextcursor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I wanted to increase spacing between paragraphs (text blocks) in QPlainTextEdit, to no avail. After experimenting I found that though some format properties (e.g., background color) take effect, others (e.g., margins) are ignored.
I found this bug report, but it mentions only QTextBlockFormat::lineHeight()
. In my case, almost all methods of QTextBlockFormat::*
are ignored. A minimal example:
#include <QtWidgets>
int main(int argc, char *argv) {
QApplication a(argc, argv);
QPlainTextEdit te;
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(600);
fmt.setIndent(20);
fmt.setTopMargin(600);
fmt.setLeftMargin(40);
cursor.setBlockFormat(fmt);
te.show();
return a.exec();
}
Except fmt.setBackground(QColor(Qt::yellow))
, others are all ignored. Using Qt 5.10.
c++ qt qt5 qplaintextedit qtextcursor
I wanted to increase spacing between paragraphs (text blocks) in QPlainTextEdit, to no avail. After experimenting I found that though some format properties (e.g., background color) take effect, others (e.g., margins) are ignored.
I found this bug report, but it mentions only QTextBlockFormat::lineHeight()
. In my case, almost all methods of QTextBlockFormat::*
are ignored. A minimal example:
#include <QtWidgets>
int main(int argc, char *argv) {
QApplication a(argc, argv);
QPlainTextEdit te;
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(600);
fmt.setIndent(20);
fmt.setTopMargin(600);
fmt.setLeftMargin(40);
cursor.setBlockFormat(fmt);
te.show();
return a.exec();
}
Except fmt.setBackground(QColor(Qt::yellow))
, others are all ignored. Using Qt 5.10.
c++ qt qt5 qplaintextedit qtextcursor
c++ qt qt5 qplaintextedit qtextcursor
edited Nov 15 at 16:16
eyllanesc
71.3k93053
71.3k93053
asked Nov 15 at 16:15
Maximko
11719
11719
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Don't use QPlainTextEdit
for intensive formatting over text. Use its cousin, QTextEdit
instead.
Using your code and changing it from QPlainTextEdit
to QTextEdit
resolved the issue.
FYI, this was also mentioned in the Bug Report you linked. Maybe you missed it or forgot to mention it in your question?
Replacing QPlainTextEdit with QTextEdit shows the expected result.
QTextEdit te; // note the change in type
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(6); // let's not overexaggerate anything
fmt.setIndent(1);
fmt.setTopMargin(12);
fmt.setLeftMargin(1);
cursor.setBlockFormat(fmt);
Here's the result of using QPlainTextEdit
(on a MacOS).
And here's the result of using QTextEdit
(on a MacOS).
Note that none of the member functions need to be modified, so that's a plus. Transitioning from QPlainTextEdit
to QTextEdit
shouldn't be much of a pain.
Further Reading: This other SO post kinda helped. Would also be good to read if you're planning on using more Qt Text Classes.
Yes, I know that it works for QTextEdit :) For certain reasons, however, I am confined to deal with QPlainTextEdit. And so it looks not much as a bug, but as documented feature of a class (QPlainTextEdit) which in fact is merely not implemented....
– Maximko
Nov 26 at 15:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323628%2fqplaintextedit-ignores-most-of-the-text-block-formats%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Don't use QPlainTextEdit
for intensive formatting over text. Use its cousin, QTextEdit
instead.
Using your code and changing it from QPlainTextEdit
to QTextEdit
resolved the issue.
FYI, this was also mentioned in the Bug Report you linked. Maybe you missed it or forgot to mention it in your question?
Replacing QPlainTextEdit with QTextEdit shows the expected result.
QTextEdit te; // note the change in type
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(6); // let's not overexaggerate anything
fmt.setIndent(1);
fmt.setTopMargin(12);
fmt.setLeftMargin(1);
cursor.setBlockFormat(fmt);
Here's the result of using QPlainTextEdit
(on a MacOS).
And here's the result of using QTextEdit
(on a MacOS).
Note that none of the member functions need to be modified, so that's a plus. Transitioning from QPlainTextEdit
to QTextEdit
shouldn't be much of a pain.
Further Reading: This other SO post kinda helped. Would also be good to read if you're planning on using more Qt Text Classes.
Yes, I know that it works for QTextEdit :) For certain reasons, however, I am confined to deal with QPlainTextEdit. And so it looks not much as a bug, but as documented feature of a class (QPlainTextEdit) which in fact is merely not implemented....
– Maximko
Nov 26 at 15:42
add a comment |
up vote
0
down vote
Don't use QPlainTextEdit
for intensive formatting over text. Use its cousin, QTextEdit
instead.
Using your code and changing it from QPlainTextEdit
to QTextEdit
resolved the issue.
FYI, this was also mentioned in the Bug Report you linked. Maybe you missed it or forgot to mention it in your question?
Replacing QPlainTextEdit with QTextEdit shows the expected result.
QTextEdit te; // note the change in type
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(6); // let's not overexaggerate anything
fmt.setIndent(1);
fmt.setTopMargin(12);
fmt.setLeftMargin(1);
cursor.setBlockFormat(fmt);
Here's the result of using QPlainTextEdit
(on a MacOS).
And here's the result of using QTextEdit
(on a MacOS).
Note that none of the member functions need to be modified, so that's a plus. Transitioning from QPlainTextEdit
to QTextEdit
shouldn't be much of a pain.
Further Reading: This other SO post kinda helped. Would also be good to read if you're planning on using more Qt Text Classes.
Yes, I know that it works for QTextEdit :) For certain reasons, however, I am confined to deal with QPlainTextEdit. And so it looks not much as a bug, but as documented feature of a class (QPlainTextEdit) which in fact is merely not implemented....
– Maximko
Nov 26 at 15:42
add a comment |
up vote
0
down vote
up vote
0
down vote
Don't use QPlainTextEdit
for intensive formatting over text. Use its cousin, QTextEdit
instead.
Using your code and changing it from QPlainTextEdit
to QTextEdit
resolved the issue.
FYI, this was also mentioned in the Bug Report you linked. Maybe you missed it or forgot to mention it in your question?
Replacing QPlainTextEdit with QTextEdit shows the expected result.
QTextEdit te; // note the change in type
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(6); // let's not overexaggerate anything
fmt.setIndent(1);
fmt.setTopMargin(12);
fmt.setLeftMargin(1);
cursor.setBlockFormat(fmt);
Here's the result of using QPlainTextEdit
(on a MacOS).
And here's the result of using QTextEdit
(on a MacOS).
Note that none of the member functions need to be modified, so that's a plus. Transitioning from QPlainTextEdit
to QTextEdit
shouldn't be much of a pain.
Further Reading: This other SO post kinda helped. Would also be good to read if you're planning on using more Qt Text Classes.
Don't use QPlainTextEdit
for intensive formatting over text. Use its cousin, QTextEdit
instead.
Using your code and changing it from QPlainTextEdit
to QTextEdit
resolved the issue.
FYI, this was also mentioned in the Bug Report you linked. Maybe you missed it or forgot to mention it in your question?
Replacing QPlainTextEdit with QTextEdit shows the expected result.
QTextEdit te; // note the change in type
te.setPlainText("block1nblock2nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(6); // let's not overexaggerate anything
fmt.setIndent(1);
fmt.setTopMargin(12);
fmt.setLeftMargin(1);
cursor.setBlockFormat(fmt);
Here's the result of using QPlainTextEdit
(on a MacOS).
And here's the result of using QTextEdit
(on a MacOS).
Note that none of the member functions need to be modified, so that's a plus. Transitioning from QPlainTextEdit
to QTextEdit
shouldn't be much of a pain.
Further Reading: This other SO post kinda helped. Would also be good to read if you're planning on using more Qt Text Classes.
answered Nov 16 at 15:35
TrebuchetMS
1,7711618
1,7711618
Yes, I know that it works for QTextEdit :) For certain reasons, however, I am confined to deal with QPlainTextEdit. And so it looks not much as a bug, but as documented feature of a class (QPlainTextEdit) which in fact is merely not implemented....
– Maximko
Nov 26 at 15:42
add a comment |
Yes, I know that it works for QTextEdit :) For certain reasons, however, I am confined to deal with QPlainTextEdit. And so it looks not much as a bug, but as documented feature of a class (QPlainTextEdit) which in fact is merely not implemented....
– Maximko
Nov 26 at 15:42
Yes, I know that it works for QTextEdit :) For certain reasons, however, I am confined to deal with QPlainTextEdit. And so it looks not much as a bug, but as documented feature of a class (QPlainTextEdit) which in fact is merely not implemented....
– Maximko
Nov 26 at 15:42
Yes, I know that it works for QTextEdit :) For certain reasons, however, I am confined to deal with QPlainTextEdit. And so it looks not much as a bug, but as documented feature of a class (QPlainTextEdit) which in fact is merely not implemented....
– Maximko
Nov 26 at 15:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323628%2fqplaintextedit-ignores-most-of-the-text-block-formats%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown