我有一个简单的程序,我需要显示日文字符。它有点奇怪的行为(在我看来),有时它会显示字符,有时它会像方格一样显示。
我的程序逻辑是启动向量,包含字母InitAlphabet();
,然后随机选择一个字符painter.drawStaticText(0, 0, alphabet[randomNumb]);
。
你能告诉我为什么会这样吗? 代码:
private:
Ui::Widget *ui;
QVector<QString> alphabet;
QVector<QString> translation;
int randomNumb;
void Widget::InitAlphabet()
{
alphabet.push_back("あ");
alphabet.push_back("い");
alphabet.push_back("う");
alphabet.push_back("え");
alphabet.push_back("お");
alphabet.push_back("か");
alphabet.push_back("き");
alphabet.push_back("く");
alphabet.push_back("け");
alphabet.push_back("こ");
alphabet.push_back("さ");
alphabet.push_back("し");
alphabet.push_back("す");
alphabet.push_back("せ");
alphabet.push_back("そ");
alphabet.push_back("た");
alphabet.push_back("ち");
alphabet.push_back("つ");
alphabet.push_back("て");
alphabet.push_back("と");
alphabet.push_back("な");
alphabet.push_back("に");
alphabet.push_back("ぬ");
alphabet.push_back("ね");
alphabet.push_back("の");
alphabet.push_back("は");
alphabet.push_back("ひ");
alphabet.push_back("ふ");
alphabet.push_back("へ");
alphabet.push_back("ほ");
alphabet.push_back("ま");
alphabet.push_back("み");
alphabet.push_back("む");
alphabet.push_back("め");
alphabet.push_back("も");
alphabet.push_back("や");
alphabet.push_back("ゆ");
alphabet.push_back("よ");
alphabet.push_back("ら");
alphabet.push_back("り");
alphabet.push_back("る");
alphabet.push_back("れ");
alphabet.push_back("ろ");
alphabet.push_back("わ");
alphabet.push_back("ん");
}
int Widget::getRandomNumber()
{
return qrand() % alphabet.length();
}
void Widget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawStaticText(0, 0, alphabet[randomNumb]);
// painter.drawStaticText(50, 50, translation[randomNumb]);
}