This commit is contained in:
2026-04-25 16:33:53 +08:00
parent c567fc1e66
commit 49b1860afe
8 changed files with 320 additions and 314 deletions
+19 -54
View File
@@ -1,66 +1,31 @@
# 数字软键盘
# NumKeyBoard
## qmake作为pri使用
`Libs/NumKeyBoard` is the shared numeric keyboard library used by both `TGcs` and `LauncherLib`.
- 将文件夹复制到主工程Libs目录下
- 主工程pro文件中加入:
## qmake
Build the library from `TGcsProject.pro` or `Libs/NumKeyBoard/NumKeyBoard.pro`, then link it from consumer projects:
```qmake
include($$PWD/Libs/SoftNumKeyBoard/NumKeyBoard.pri)
unix|win32: LIBS += -L$$PWD/Build/Libs/ -lNumKeyBoard
INCLUDEPATH += $$PWD/Libs/NumKeyBoard
DEPENDPATH += $$PWD/Libs/NumKeyBoard
```
- 主工程中重写eventFilter函数,实现点击lineedit时,调出小键盘
## API
Use the shared singleton-style keyboard API:
```cpp
protected:
virtual bool eventFilter(QObject * obj, QEvent *event) override;
```
```cpp
bool SettingWidget::eventFilter(QObject *obj, QEvent * event)
auto *keyboard = KeyBoard::app();
if(!keyboard)
{
auto _obj = static_cast<QLineEdit *>(obj);
if(m_inputList.contains(_obj))
{
if(event->type() == QEvent::FocusIn)
{
if(!_keyBoard)
{
_keyBoard = new NumKeyDia(this);
}
//传入对应的QLineEdit
_keyBoard->setPLineEdit(_obj);
_keyBoard->exec();
//QLineEdit取消聚焦,可以不用
_obj->clearFocus();
return true;
}
}
return QObject::eventFilter(obj, event);
keyboard = new NumKeyDia;
}
keyboard->setValue(lineEdit->text());
keyboard->exec();
lineEdit->setText(keyboard->getValue());
```
- 对应的控件安装事件过滤器
```cpp
m_inputList = this->findChildren<QLineEdit *>();
foreach (auto &i, m_inputList)
{
i->installEventFilter(this);
i->setFocusPolicy(Qt::ClickFocus);
}
```
- 控件设置属性
```cpp
//设置输入输出的最大值、最小值、名字和是否是数字
ui->lineEdit_energyA->setProperty("IsNum", true);
//double时,默认保留三位小数
ui->lineEdit_energyA->setProperty("IsDouble", true);
//输入的数不能超过最大值和最小值
ui->lineEdit_energyA->setProperty("Max", 1.000);
ui->lineEdit_energyA->setProperty("Min", 0.000);
ui->lineEdit_energyA->setProperty("Name", tr("PressureA"));
```
The old `setPLineEdit` / range-validation API is no longer part of the shared library.