Solved How to insert rows one by one in QTextedit.
-
I have a QTextEdit and 2 QStringLists( L1 and L2 ) with numbers.
I want get this:
L1[0] L1[1] L1[2] L1[3]
L2[0] L2[2] L2[2] L2[3]
L1[4] L1[5] L1[6] L1[7]
L2[4] L2[5] L2[6] L2[7] -
@Anton-Shelenkov
So print out your desired numbers in an appropriate loops (probably 4 of them), and send a newline (\n
) at the end of each row to break them into lines. (Use http://doc.qt.io/qt-5/qtextedit.html#setPlainText and/or http://doc.qt.io/qt-5/qtextedit.html#append) What's the issue withQTextEdit
otherwise? -
@JonB
I wrote not exactly. I need to fill the line completely, depending on the size of the TextEdit. (If the screen is wide, then all 18 numbers are relevant in the line, and if narrow then 4 will have to be written in new lines). I hope so I understood more clearly.I do not understand how to get the size of a string of text edita or check whether the end of line is reached..
-
@Anton-Shelenkov
Hopefully you will not need to do that. See http://doc.qt.io/qt-5/qtextedit.html#LineWrapMode-enum. Isn'tsetLineWrapMode(QTextEdit::WidgetWidth)
what you are wanting? -
@JonB Thanks for answer, but in my case it's not correct solution.
I know solution, but i don't know how check "endl" in text edit.
-
@Anton-Shelenkov said in How to insert rows one by one in QTextedit.:
but i don't know how check "endl" in text edit.
Sorry, no idea what this means.
-
Hi
If you mean you want to make the word wrapping yourself, and need to know the pixel width of random text, it goes something likeQFont myFont(fontName, fontSize);; QString str("I wonder how wide this is?"); QFontMetrics fm(myFont); int width=fm.width(str);
But you would have to use the font , that TextEdit will use for that paragraph when it draws it.
If you only use the default font for all paragraphs, your should be able to do something
QPlainTextEdit monoEdit;
QTextDocument *doc = monoEdit.document();
QFont font = doc->defaultFont(); -
@mrjj Thanks.