Qt Designer, QTextEdit, remove indentation
-
Hi, in Qt Designer i add a QTextEdit and a QLabel widget. The default seems to be a border?/margin?/padding?/indentation? of 4px. I'm not sure what the extra space is but the label has an option to change the indentation which can remove the extra space on all four sides.
But the textedit does not have this option as far as i know. I want the textedit to have zero 'border space'. The stylesheet sort of gives me what i want if i change the margin or padding to -4px. But that still leaves unwanted space on the right and bottom.Is there an easy solution for this? Thanks.
-
Hi
You mean you have them in layout and there is margin ?
Layout have default margins, you can set to zero. -
Hi
I think its
setViewportMargins(0, 0, 0, 0);(incorrect) and also zero as default.
but i didnt test.its protected function.
-
Thanks for the suggestion. Doesn't work though. It's at 0,0,0,0 margin to begin with and it doesn't change if i set it again. Only if i set left and top to -4 does it 'fix' it.
Somehow somewhere it adds those 4 or 5 pixels on all sides of the text content.
-
-
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
Android phone A34
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 ?