title: Set line spacing in QTextEdit
body: <p>I want to set the line spacing of a QTextEdit.</p>
  
  <p>It's no problem to get that information with </p>
  
  <pre><code>QFontMetrics::lineSpacing();
  </code></pre>
  
  <p><strong>But how to set that?</strong></p>
  
  <p>I tried with StyleSheets, but that didn't work:</p>
  
  <pre><code>this-&gt;setStyleSheet("QTextEdit{ height: 200%; }");
  </code></pre>
  
  <p>or</p>
  
  <pre><code>this-&gt;setStyleSheet("QTextEdit{ line-height: 200%; }");
  </code></pre>
  
  <p><strong>Partial solution:</strong></p>
  
  <p>Well, I've found a solution - not the way I wanted it, but at least it's simple and it gives nearly my intended behavior, enough for my proof of concept. </p>
  
  <p>On every new line there's some linespacing. But if you just type until the text is automatically wrapped to a new line you wont have line-spacing between this two lines. This hack only works with text blocks, see the code.</p>
  
  <p>Just keep in mind it's brute force and a ugly hack. But it provides some kind of line-spacing to your beautiful QTextEdit. Call it everytime your text changes.</p>
  
  <pre><code>void setLineSpacing(int lineSpacing) {
      int lineCount = 0;
      for (QTextBlock block = this-&gt;document()-&gt;begin(); block.isValid();
              block = block.next(), ++lineCount) {
          QTextCursor tc = QTextCursor(block);
          QTextBlockFormat fmt = block.blockFormat();
          if (fmt.topMargin() != lineSpacing
                  || fmt.bottomMargin() != lineSpacing) {
              fmt.setTopMargin(lineSpacing);
              //fmt.setBottomMargin(lineSpacing);
              tc.setBlockFormat(fmt);
          }
      }
  }
  </code></pre>