Hello, I reply this old topic but I could not find a solution for a problem. I want to set the padding of the text editor to zero.
textEdit->document()->setDocumentMargin(0);
as @mpergand said this works. However when I try to design application for different platform a problem occurred.
On the mac the text is fit all the width of the texteditor, but in android there is always a small space at the end.
Both text editors' width set to 150, on mac 45 of letter i can fit, on the phone 44i can fit and the small space.
MAC
Screen Shot 2024-06-29 at 12.56.12.png
Android phone A34
mobile.png
I tried all the below , none of them works
part of the code:
QTextDocument *doc = textEdit->document();
doc->setDocumentMargin(0);
doc->setIndentWidth(0);
textEdit->setContentsMargins(0,0,0,0);
// textEdit->set
QTextCursor cursor(doc);
// Select the entire text
cursor.select(QTextCursor::Document);
// Create a character format and set the font style
QTextCharFormat format;
// QFont font("Arial", 12, QFont::Bold); // Example: Arial, 12pt, bold
format.setFont(timesFont);
// Apply the format to the selected text
cursor.mergeCharFormat(format);
// Set block format to ensure no extra margins
QTextBlockFormat blockFormat;
blockFormat.setBottomMargin(0);
blockFormat.setTopMargin(0);
blockFormat.setLeftMargin(0);
blockFormat.setRightMargin(0);
cursor.setBlockFormat(blockFormat);
textEdit->setTextCursor(cursor);
Why there is a difference ?