Qt Designer, QTextEdit, remove indentation
-
wrote on 10 Jan 2018, 11:56 last edited by Tink 1 Oct 2018, 13:56
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. -
wrote on 10 Jan 2018, 12:22 last edited by
I'm sorry, i should have been more clear.
The margin is within the QTextEdit itself. Space between text and frame border. -
Lifetime Qt Championwrote on 10 Jan 2018, 12:30 last edited by mrjj 1 Nov 2018, 07:11
Hi
I think its
setViewportMargins(0, 0, 0, 0);(incorrect) and also zero as default.
but i didnt test.its protected function.
-
wrote on 10 Jan 2018, 13:48 last edited by Tink 1 Oct 2018, 13:57
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.
-
wrote on 10 Jan 2018, 14:15 last edited by
try:
textEdit->document()->setDocumentMargin(0);
-
wrote on 10 Jan 2018, 14:25 last edited by
@mpergand said in Qt Designer, QTextEdit, remove indentation:
try:
textEdit->document()->setDocumentMargin(0);
Yes! This works!
Thank you! -
-
wrote on 29 Jun 2024, 10:15 last edited by
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.
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 ?
5/8