You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tianzhendong
4c6b403a70
|
11 months ago | |
---|---|---|
NumKeyBoard.pri | 11 months ago | |
NumKeyBoard.pro | 11 months ago | |
README.md | 11 months ago | |
numkeydia.cpp | 11 months ago | |
numkeydia.h | 11 months ago | |
numkeydia.ui | 11 months ago |
README.md
数字软键盘
qmake作为pri使用
- 将文件夹复制到主工程Libs目录下
- 主工程pro文件中加入:
include($$PWD/Libs/SoftNumKeyBoard/NumKeyBoard.pri)
- 主工程中重写eventFilter函数,实现点击lineedit时,调出小键盘
protected:
virtual bool eventFilter(QObject * obj, QEvent *event) override;
bool SettingWidget::eventFilter(QObject *obj, QEvent * event)
{
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);
}
- 对应的控件安装事件过滤器
m_inputList = this->findChildren<QLineEdit *>();
foreach (auto &i, m_inputList)
{
i->installEventFilter(this);
i->setFocusPolicy(Qt::ClickFocus);
}
- 控件设置属性
//设置输入输出的最大值、最小值、名字和是否是数字
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"));