轻量级Qt键盘-兼容Qt4
- 啊南
- 210阅读
- 2021.01.18
在原有的键盘基础上兼容Qt4版本。
- 由于QScroller类在Qt5引入,故添加条件宏:
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include#endif #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) /* 设置鼠标左键拖动 */ QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture); #endif
- 为了更好兼容Qt 4版本,对C++11的「R面量字符串」更改。
将:
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; } )");
改为:
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不支持>>需要使用空格分开
将:
QList>
改为:
QList>
- C++98不支持for的直接范围循环
将:
const QList> &tmp = m_data[text.left(1)]; for (const QPair &each : tmp) { ... }
改为:
const QList> &tmp = m_data[text.left(1)]; for (int i = 0; i < tmp.count(); i++) { const QPair &each = tmp.at(i); ... }
- C++98不支持列表初始化
将:
const QListmodeListBar4 = { {{Qt::Key_Mode_switch, "", "?123"}}, {{Qt::Key_Context1, "", "En"}, {Qt::Key_Context1, "", "中"}}, {{Qt::Key_Space, " ", ""/*空格*/}}, {{Qt::Key_Enter, "", ""/*换行*/}} };
改为:
static QListmodeListBar_4() { QList 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 modeListBar4 = modeListBar_4();