title: How to format the selected text in a QTextEdit by pressing a button
body: <p>I want to format a selected text in a QTextEdit by clicking a button. For axample I want to make it bold if it is not-bold, or not-bold if it is bold. Please help me with an example.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Actually I have found already a code - qt demo for text editor which does what I need:</p>
  
  <pre><code>void
  MyTextEdit::boldText(bool isBold) //this is the SLOT for the button trigger(bool)
  {
      QTextCharFormat fmt;
      fmt.setFontWeight(isBold ? QFont::Bold : QFont::Normal);
      mergeFormatOnWordOrSelection(fmt);
  }
  
  void
  MyTextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &amp;format)
   {
       QTextCursor cursor = m_textEdit-&gt;textCursor();
       if (!cursor.hasSelection())
           cursor.select(QTextCursor::WordUnderCursor);
       cursor.mergeCharFormat(format);
       m_textEdit-&gt;mergeCurrentCharFormat(format);
   }
  </code></pre>
  
  <p>But I can't understand what returnes the <em>textCursor()</em> method, and how the merging of properties is being done? Just some formats are being changed, some of them stay constant. How <em>mergeCharFormat</em> function understands what to change and what to leave as is. Please explain me just these 2 things. 
  Thanks.</p>