Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Designer, QTextEdit, remove indentation
QtWS25 Last Chance

Qt Designer, QTextEdit, remove indentation

Scheduled Pinned Locked Moved Solved General and Desktop
qtexteditindentation
8 Posts 4 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tink
    wrote on 10 Jan 2018, 11:56 last edited by Tink 1 Oct 2018, 13:56
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 10 Jan 2018, 12:04 last edited by
      #2

      Hi
      You mean you have them in layout and there is margin ?
      Layout have default margins, you can set to zero.

      1 Reply Last reply
      2
      • T Offline
        T Offline
        Tink
        wrote on 10 Jan 2018, 12:22 last edited by
        #3

        I'm sorry, i should have been more clear.
        The margin is within the QTextEdit itself. Space between text and frame border.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 10 Jan 2018, 12:30 last edited by mrjj 1 Nov 2018, 07:11
          #4

          Hi
          I think its
          setViewportMargins(0, 0, 0, 0); (incorrect) and also zero as default.
          but i didnt test.

          its protected function.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tink
            wrote on 10 Jan 2018, 13:48 last edited by Tink 1 Oct 2018, 13:57
            #5

            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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mpergand
              wrote on 10 Jan 2018, 14:15 last edited by
              #6

              try:

              textEdit->document()->setDocumentMargin(0);
              
              T 1 Reply Last reply 10 Jan 2018, 14:25
              5
              • M mpergand
                10 Jan 2018, 14:15

                try:

                textEdit->document()->setDocumentMargin(0);
                
                T Offline
                T Offline
                Tink
                wrote on 10 Jan 2018, 14:25 last edited by
                #7

                @mpergand said in Qt Designer, QTextEdit, remove indentation:

                try:

                textEdit->document()->setDocumentMargin(0);
                

                Yes! This works!
                Thank you!

                1 Reply Last reply
                2
                • M mpergand referenced this topic on 24 Jan 2024, 15:35
                • D Offline
                  D Offline
                  DeveloperQt
                  wrote on 29 Jun 2024, 10:15 last edited by
                  #8

                  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 ?

                  1 Reply Last reply
                  0

                  5/8

                  10 Jan 2018, 13:48

                  • Login

                  • Login or register to search.
                  5 out of 8
                  • First post
                    5/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved