QPlainTextEdit - Multiline edit box
-
Allo,
How can I change the line spacing for QPlainTextEdit?
I find that the line spacing is too much. -
-
@JonB I looked at the 3 links and to be honest, I am lost.
For example:
https://stackoverflow.com/questions/10317845/qplaintextedit-line-spacingIs there an example as to how to use QTextBlockFormat?
I have never been able to figure out how to use a class from the documents at
https://doc.qt.io/qt-5/qtextblockformat.htmlIf I know how to use a class and I just want to change the color or size or something, then those pages are useful since they somewhat explain how to use a member function.
Please keep in mind that we are not all equal.
Perhaps you have the skills to not know anything about Qt, and read those docs and write a full program. I don’t.
I started to learn Qt by looking at the various sample projects that came with Qt Creator. -
@stretchthebits said in QPlainTextEdit - Multiline edit box:
Is there an example as to how to use QTextBlockFormat?
Did you progress to the second link which has a code block showing the usage of
QTextBlockFormat
? Did you try that out? Or the third one, which also has examples usingQTextBlockFormat
? -
Hi
If you change your QPlainTextEdit to a QTextEdit.
(you can right click it in Designer , use the morph menu)Then the following code will set line-height to 10
void MainWindow::on_pushButton_4_released()
{
QTextEdit * te = ui->textEdit;
// get a cursor for selection
QTextCursor cursor = te->textCursor();
// select all
cursor.select(QTextCursor::Document);
// declare a Block
QTextBlockFormat fmt;
//set wanted line height. YTou might want to use fmt.lineHeight() to get current value
fmt.setLineHeight(10, QTextBlockFormat::FixedHeight);
// set the format. if you have other formatting, you might want to use mergeformat()
cursor.setBlockFormat(fmt);
} -
@mrjj said in QPlainTextEdit - Multiline edit box:
Hi
If you change your QPlainTextEdit to a QTextEdit.
(you can right click it in Designer , use the morph menu)Then the following code will set line-height to 10
void MainWindow::on_pushButton_4_released()
{
QTextEdit * te = ui->textEdit;
// get a cursor for selection
QTextCursor cursor = te->textCursor();
// select all
cursor.select(QTextCursor::Document);
// declare a Block
QTextBlockFormat fmt;
//set wanted line height. YTou might want to use fmt.lineHeight() to get current value
fmt.setLineHeight(10, QTextBlockFormat::FixedHeight);
// set the format. if you have other formatting, you might want to use mergeformat()
cursor.setBlockFormat(fmt);
}Thanks. That seems to work. I just need to give control for the line spacing to the user now.