// completertextedit.h #ifndef COMPLETERTEXTEDIT_H #define COMPLETERTEXTEDIT_H #include #include #include "WellLogUI.h" QT_BEGIN_NAMESPACE class QCompleter; QT_END_NAMESPACE class OSGWELLLOGUI_EXPORT CompleterTextEdit : public QTextEdit { Q_OBJECT public: explicit CompleterTextEdit(QWidget *parent = 0); ~CompleterTextEdit() { // if(m_completer) delete m_completer; } void setCompleter(QCompleter *completer); QCompleter * GetCompleter(); protected: void keyPressEvent(QKeyEvent *e); // 响应按键盘事件 void keyReleaseEvent(QKeyEvent *e); virtual void mousePressEvent(QMouseEvent *e); private slots: void onCompleterActivated(const QString &completion); // 响应选中QCompleter中的选项后,QCompleter发出的activated()信号 private: QString wordUnderCursor(); // 获取当前光标所在的单词 private: QCompleter *m_completer; }; #endif // COMPLETERTEXTEDIT_H1