How to judge there is content in QTextEdit?
-
Hi All,
I'm trying to judge whether there is content in QTextEdit or not.
If there is content inside, I want to use "append" to show more information in TextEdit.
If not then I want to use "SetText" to show it.How can I do that?
Is there any element like "isEmpty"? -
Hi All,
I'm trying to judge whether there is content in QTextEdit or not.
If there is content inside, I want to use "append" to show more information in TextEdit.
If not then I want to use "SetText" to show it.How can I do that?
Is there any element like "isEmpty"?@victor-wang said in How to judge there is content in QTextEdit?:
If there is content inside, I want to use "append" to show more information in TextEdit.
If not then I want to use "SetText" to show it.Why?
append()
still works when the QTextEdit is empty.Is there any element like "isEmpty"?
Not quite, but you can call
textEdit->document()->characterCount()
;Note: Empty documents have
characterCount() == 1
(not 0) -
@victor-wang said in How to judge there is content in QTextEdit?:
If there is content inside, I want to use "append" to show more information in TextEdit.
If not then I want to use "SetText" to show it.Why?
append()
still works when the QTextEdit is empty.Is there any element like "isEmpty"?
Not quite, but you can call
textEdit->document()->characterCount()
;Note: Empty documents have
characterCount() == 1
(not 0)@JKSH
I did try to use append to show text in empty QTextEdit.
However, it didn't show anything unless I use "Settext" at the first time then "append".
This confused me too.
That's why I try to get another way to solve it. -
@JKSH
I did try to use append to show text in empty QTextEdit.
However, it didn't show anything unless I use "Settext" at the first time then "append".
This confused me too.
That's why I try to get another way to solve it.@victor-wang said in How to judge there is content in QTextEdit?:
However, it didn't show anything unless I use "Settext" at the first time then "append".
That's strange. Which version of Qt? This code works for me on Qt 5.12.0 (MinGW 7.3.0, 64-bit):
QTextEdit e; e.append("Hello"); e.show();