❝在原有的键盘基础上兼容Qt4版本。❞
- 由于QScroller类在Qt5引入,故添加条件宏:
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include <QScroller>
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
/* 设置鼠标左键拖动 */
QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture);
#endif
- 为了更好兼容Qt 4版本,对C 11的「R面量字符串」更改。
将:
代码语言:javascript复制setStyleSheet(R"(
QListWidget { outline: none; border:1px solid #00000000; color: black; }
QListWidget::Item { width: 50px; height: 50px; }
QListWidget::Item:hover { background: #4395ff; color: white; }
QListWidget::item:selected { background: #4395ff; color: black; }
QListWidget::item:selected:!active { background: #00000000; color: black; }
)");
改为:
代码语言:javascript复制setStyleSheet("
QListWidget { outline: none; border:1px solid #00000000; color: black; }
QListWidget::Item { width: 50px; height: 50px; }
QListWidget::Item:hover { background: #4395ff; color: white; }
QListWidget::item:selected { background: #4395ff; color: black; }
QListWidget::item:selected:!active { background: #00000000; color: black; }
");
- C 98不支持
>>
需要使用空格分开
将:
代码语言:javascript复制QList<QPair<QString, QString>>
改为:
代码语言:javascript复制QList<QPair<QString, QString> >
- C 98不支持for的直接范围循环
将:
代码语言:javascript复制const QList<QPair<QString, QString>> &tmp = m_data[text.left(1)];
for (const QPair<QString, QString> &each : tmp) {
...
}
改为:
代码语言:javascript复制const QList<QPair<QString, QString> > &tmp = m_data[text.left(1)];
for (int i = 0; i < tmp.count(); i ) {
const QPair<QString, QString> &each = tmp.at(i);
...
}
- C 98不支持列表初始化
将:
代码语言:javascript复制const QList<Modes> modeListBar4 = {
{{Qt::Key_Mode_switch, "", "?123"}},
{{Qt::Key_Context1, "", "En"}, {Qt::Key_Context1, "", "中"}},
{{Qt::Key_Space, " ", ""/*空格*/}},
{{Qt::Key_Enter, "", ""/*换行*/}}
};
改为:
代码语言:javascript复制static QList<Modes> modeListBar_4()
{
QList<Modes> modesList;
Modes modes1;
modes1 << KeyButton::Mode(Qt::Key_Mode_switch, "", "?123");
Modes modes2;
modes2 << KeyButton::Mode(Qt::Key_Context1, "", "En");
modes2 << KeyButton::Mode(Qt::Key_Context1, "", "中");
Modes modes3;
modes3 << KeyButton::Mode(Qt::Key_Space, " ", ""/*空格*/);
Modes modes4;
modes4 << KeyButton::Mode(Qt::Key_Enter, "", ""/*换行*/);
modesList << modes1 << modes2 << modes3 << modes4;
return modesList;
}
const QList<Modes> modeListBar4 = modeListBar_4();
关于更多
- 源码地址:
https://github.com/aeagean/QtKeyboard