title: Qt 5.8 QTextEdit Text Cursor Color Won't Change
body: <p>I am trying to make the text cursor on a QTextEdit red (rgb(255,0,0)). Despite my best efforts, it continues to blink white. </p>
  
  <p>From what I've found, the Style Sheet "color" property is supposed to change the color of the cursor. Not sure what's wrong.</p>
  
  <p>My Code:</p>
  
  <pre><code>    textEntry = new QTextEdit();
      textEntry-&gt;setFont(QFont("Electrolize", 9, 1));
      textEntry-&gt;setMinimumHeight(25);
      textEntry-&gt;setMaximumHeight(25);
      textEntry-&gt;setLineWrapMode(QTextEdit::NoWrap);
      textEntry-&gt;setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
      textEntry-&gt;setStyleSheet("color: rgb(255, 0, 0);"
                               "border: 1px solid rgb(255, 0, 0);");
  </code></pre>
  
  <p>Edit:
  I encourage a full read of Scheff's answer. It's awesome. I noticed that the cursor created with his solution didn't blink, though, so I wanted to share a blinking version derived from Scheff's code with my (inexperienced) addition.</p>
  
  <p>TextEdit.h</p>
  
  <pre><code>#ifndef TEXTEDIT_H
  #define TEXTEDIT_H
  
  #include &lt;QTextEdit&gt;
  #include &lt;QTimer&gt;
  
  class TextEdit : public TextEdit
  {
      Q_OBJECT
  public:
      explicit TextEdit(QWidget *parent = nullptr);
  
  private:
      QTimer *timer;
      QPainter *pPainter;
      bool bCursorVisible;
  
  protected:
      virtual void paintEvent(QPaintEvent *pEvent) override;
  
  signals:
      sendUpdate();
  
  public slots:
      void timerSlot();
  };
  
  #endif // TEXTEDIT_H
  </code></pre>
  
  <p>TextEdit.cpp</p>
  
  <pre><code>#include "textedit.h"
  
  #include &lt;QPainter&gt;
  #include &lt;QColor&gt;
  #include &lt;QTimer&gt;
  
  TextEdit::TextEdit(QWidget *parent) : QTextEdit(parent) {
      bCursorVisible = true;
  
      timer = new QTimer(this);
      timer-&gt;start(500);
      connect(this, SIGNAL(sendUpdate()), this, SLOT(update()));
      connect(timer, SIGNAL(timeout()), this, SLOT(timerSlot()));
  }
  
  void TextEdit::paintEvent(QPaintEvent *event)
  {
    // use paintEvent() of base class to do the main work
    QTextEdit::paintEvent(event);
    // draw cursor (if widget has focus)
    if (hasFocus()) {
      if(bCursorVisible) {
          const QRect qRect = cursorRect(textCursor());
          QPainter qPainter(viewport());
          qPainter.fillRect(qRect, QColor(255, 0, 0, 255));
      } else {
          const QRect qRect = cursorRect(textCursor());
          QPainter qPainter(viewport());
          qPainter.fillRect(qRect, QColor(0, 0, 0, 255));
      }
    }
  }
  
  void TextEdit::timerSlot() {
      if(bCursorVisible) {
          bCursorVisible = false;
      } else {
          bCursorVisible = true;
      }
  
      emit sendUpdate();
  }
  </code></pre>