CodeArea::CodeArea(QWidget *parent) :QPlainTextEdit(parent) ,highlighter(this->document()) { QFont font; font.setFamily("Courier"); font.setFixedPitch(true); font.setPointSize(10); font.insertSubstitution(" "," "); setFont(font); setWordWrapMode(QTextOption::NoWrap); lineNumberArea = new LineNumberArea(this); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); updateLineNumberAreaWidth(0); highlightCurrentLine(); mCompleter = new QCompleter(this); mCompleter->setModel(new QStringListModel(mWordList, mCompleter)); mCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel); mCompleter->setCaseSensitivity(Qt::CaseSensitive); mCompleter->setWrapAround(false); mCompleter->setWidget(this); mCompleter->setCompletionMode(QCompleter::PopupCompletion); mCompleter->setCaseSensitivity(Qt::CaseInsensitive); QObject::connect(mCompleter, SIGNAL(activated(QString)), this, SLOT(insertCompletion(QString))); connect(this,SIGNAL(textChanged()), this, SLOT(onTextChange())); }