QTextCursor textCursor () constvoid setTextCursor ( const QTextCursor & cursor )
typedef QTextEdit::ExtraSelection ExtraSelection;typedef QList<ExtraSelection> ExtraSelectionList;ExtraSelectionList m_Selection;void OnSelectionChanged(){ QTextCursor cursor = textCursor(); if (cursor.hasSelection()) { m_Selection.begin()->cursor = cursor; m_Selection.begin()->format.setBackground(QBrush(Qt::black)); m_Selection.begin()->format.setForeground(QBrush(Qt::white)); setExtraSelections(m_Selection); }}