Is it a bug with QTextEdit?
-
What should this piece of code look like when use WordWrap? The blank spaces are lost and i can not insert any more before "A"
@
QTextEdit *te = new QTextEdit();
te->setText(QString(" A lot blank space before"));
te->show();
@Another way to reproduce the problem: in a QTextEdit, type blank space until it wraps to the second line, then you will find you can't type any more blanks, what's more, the blanks you typed before dispeared.
-
I don't quite understand your question but it is working correctly in my opinion.
You are using "QTextOption::WordWrap":http://doc.qt.nokia.com/latest/qtextoption.html#WrapMode-enum and setting it with: @te->setWordWrapMode(QTextOption::WordWrap);@ , aren't you?
-
Thanks for your reply! May be a picture can be more clearly。
!http://www.0ttx.com/error.jpg(a picture illustrate the problem)!
below is my code in a new project, and there is nothing else.
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextEdit *te = new QTextEdit();
te->setWordWrapMode(QTextOption::WordWrap); // seems not affect the result
te->setText(QString(" A"));
te->show();
return a.exec();
}
@ -
QTextOption::WordWrap is doing what it is supposed to do:
bq. Text is wrapped at word boundaries.
If you want to add blank space at the beginning of a line you could use "NoWrap" or "ManualWrap".
-
testbugs, did u try to resize the window? :) the A should come back to the first line.
-
No, it is staying on the second line ... after resizing the window :)
-
You might want to try using QTextEdit::setPlainText instead of setText. The latter version tries to make a guess what kind of text it is dealing with (rich text or plain text).
-
[quote author="secretNinja" date="1303641377"]No, it is staying on the second line ... after resizing the window :)[/quote]
I tried your exact code and works fine for me though ...
-
I've made two copies (the code is testbugs's ;) ) and just resize the second one ... "A" goes to the second line (as it is supposed to do according to the documentation ... or at least I understand it that way).
!http://img822.imageshack.us/img822/7977/resizer.png(resize)!
-
I confirm the same behavior secretNinja :)
-
the problem is when "A" goes to the second line, the blank spaces before "A" disappeared. If i want to input two lines of blank spaces, what should i do in a wordwrap mode? Must I use ManualWrap to implement this myself?
-
[quote author="chetankjain" date="1303641793"][quote author="secretNinja" date="1303641377"]No, it is staying on the second line ... after resizing the window :)[/quote]
I tried your exact code and works fine for me though ...[/quote]
Input more blank spaces before "A" until it goes to the sencond line, and then you will find you can not input any more blank spaces.
-
Pressing "Enter" two time do the work. Could two new lines be used instead of two lines of spaces in what you want to do?
-
[quote author="secretNinja" date="1303643751"]Pressing "Enter" two time do the work. Could two new lines be used instead of two lines of spaces in what you want to do?[/quote]
I think it is different.
I will try if I can implement this by using ManualWrap, Thanks everybody!