说明
程序应用场景:window电脑,Linux电脑直接调用系统键盘,嵌入式触摸屏开发板,需要自己写不能直接调用,涉及代码量较多,不在这里进行举例说明,可直接下载源代码例子。这是我很久以前写的例子了,就可能会有很多问题,现在更改过的我又懒得打包。
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setAutoSipEnabled(true);
TestAnn w;
w.showMaximized();
return a.exec();
}
触摸屏点击LineEdit弹出键盘需要重写QLineEdit类,下面是键盘弹出回传数据显示部分代码展示
void MainWindow::lineEditClickedVirtualkeyboard()
{
QLineEdit* lineedit = (QLineEdit*)sender();
lineeditname = lineedit->objectName();
lineedit->setStyleSheet("background-color: rgb(252, 233, 79); border-style: outset;border-width: 2px;border-radius:10px; border-color: rgb(52, 101, 164);min-width:2em;padding: 5px;");
VirtualKeyboard *v = new VirtualKeyboard;
connect(this,SIGNAL(sendData(QString)),v,SLOT(reciverData(QString)));
emit sendData(NULL);
v->setWindowModality(Qt::ApplicationModal);
v->show();
}
void MainWindow::lineEditClickedDigitalkeyboard()
{
QLineEdit* lineedit = (QLineEdit*)sender();
lineeditname = lineedit->objectName();
lineedit->setStyleSheet("background-color: rgb(252, 233, 79); border-style: outset;border-width: 2px;border-radius:10px; border-color: rgb(52, 101, 164);min-width:2em;padding: 5px;");
DigitalKeyboard *v = new DigitalKeyboard;
connect(this,SIGNAL(sendData(QString)),v,SLOT(reciverData(QString)));
emit sendData(NULL);
v->setWindowModality(Qt::ApplicationModal);
v->show();
}
void MainWindow::textview()
{
QLineEdit *lineedit = this->findChild<QLineEdit *>(lineeditname);
lineedit->setText(VirtualkeyboardAndDigitalkeyboardData);
}
void MainWindow::Timer_1()
{
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(textview()));
timer->start(30);
}
例子运行环境,Linux下QT5.12.2板子,开线程和定时器用信号与槽完成 链接:https://pan.baidu.com/s/11QteT9t_VIqaJbMnLSElsA ; 提取码:efol 有需自取
总结
抛砖引玉,自己手搓输入法真的难受,有点烦不知道要不要做个越南文的输入键盘,工作真麻烦!
|