QTextEdit change total alignment
-
When there is no text selected in my QTextEdit, i want to be able to change the text alignment of all the text in my QTextEdit. Changing the alignment of QTextEdit seems to only change the first paragraph though. Is there a way to change all of the text at once? Thanks
-
Move the cursor through all paragraphs and set their alignment. You can check the algorithm of "this solution in Python":http://www.thetoryparty.com/2009/05/14/fun-with-pyqt-setting-alignment-of-all-paragraphs-in-a-qtextedit/ and to port it to C++.
-
10 years later and the answer still works perfectly well
( ͡° ͜ʖ ͡°)
What is interesting, is that (at least in my case), the input QTextEdit actually formats the entirety of text using the QAlignment, however the output QTextEdit formats only the first line.
It's kind of as if the every row of NEW input (intercepted from user's keyboard) would inherit the QAlignment from the parent object, but this rule was somehow broken when setting the text programmatically from other type of object, like an array.
Hence why that function is very useful, but it still kind of makes no sense (the general behavior of QTextEdit).