worddisplayer.h
来自「Qt开发的GRE背单词软件」· C头文件 代码 · 共 52 行
H
52 行
/*
* Displays word and phonetic in corresponding color
*/
#ifndef WORDDISPLAYER_H
#define WORDDISPLAYER_H
#include <QTextEdit>
#include <QSyntaxHighlighter>
#include <QFont>
#include <QColor>
class MyHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
MyHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent){}
void setPhoneticFont (const QFont& font) { phoneticFont = font; }
void setPhoneticColor(const QColor& color) { phoneticColor = color; }
void setWordColor (const QColor& color) { wordColor = color; }
QFont getPhoneticFont() const { return phoneticFont; }
QColor getPhoneticColor() const { return phoneticColor; }
QColor getWordColor() const { return wordColor; }
protected:
virtual void highlightBlock(const QString& text);
private:
QFont phoneticFont;
QColor phoneticColor;
QColor wordColor;
};
class WordDisplayer : public QTextEdit
{
Q_OBJECT
public:
WordDisplayer(QWidget *parent = 0);
void setEnglishColor (const QColor& c) { highlighter.setWordColor (c); }
void setPhoneticColor(const QColor& c) { highlighter.setPhoneticColor(c); }
void setEnglishFont (const QFont& f) { setFont(f); }
void setPhoneticFont (const QFont& f) { highlighter.setPhoneticFont (f); }
private:
MyHighlighter highlighter;
};
#endif // WORDDISPLAYER_H
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?