worddisplayer.cpp
来自「Qt开发的GRE背单词软件」· C++ 代码 · 共 38 行
CPP
38 行
#include "WordDisplayer.h"
void MyHighlighter::highlightBlock(const QString& text)
{
QTextCharFormat wordFormat;
wordFormat.setForeground(wordColor);
QRegExp wordExpression("\\b[\\S]+\\b");
QTextCharFormat phoneticFormat;
phoneticFormat.setFont(phoneticFont);
phoneticFormat.setForeground(phoneticColor);
QRegExp phoneticExpression("\\[.*\\]|\\s");
int index = text.indexOf(wordExpression);
while (index >= 0)
{
int length = wordExpression.matchedLength();
setFormat(index, length, wordFormat);
index = text.indexOf(wordExpression, index + length);
}
index = text.indexOf(phoneticExpression);
while (index >= 0)
{
int length = phoneticExpression.matchedLength();
setFormat(index, length, phoneticFormat);
index = text.indexOf(phoneticExpression, index + length);
}
}
WordDisplayer::WordDisplayer(QWidget *parent)
: QTextEdit(parent), highlighter(document())
{
setFont(QFont("Arial", 36, QFont::Bold)); // defaults
highlighter.setPhoneticFont (QFont("TOPhonetic", 18, QFont::Light));
highlighter.setPhoneticColor(Qt::black);
highlighter.setWordColor (Qt::red);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?