#ifdef MYKEYBOARD
#include "myinputpanel.h"
#include "ui_myinputpanelform.h"
#include<qnamespace.h>
#include<QPointer>
MyInputPanel::MyInputPanel()
: QWidget(0, Qt::Tool | Qt::WindowStaysOnTopHint), //工具窗口
//lastFocusedWidget(0),
ui(new Ui::MyInputPanel)
{
lastFocusedWidget = 0;
caps_lock = 0;
punctuation = 0;
pun_shift = 0;
pun_flag = false;
ui->setupUi(this);
connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
this, SLOT(saveFocusWidget(QWidget*,QWidget*)));
keyMapping();
}
bool MyInputPanel::event(QEvent *e)
{
switch (e->type()) {
//! [1]
case QEvent::WindowActivate:
if (lastFocusedWidget)//激活最后一次有光标的窗口
lastFocusedWidget->activateWindow();
break;
//! [1]
default:
break;
}
return QWidget::event(e);//其它事件默认,必须要有
}
//! [2]
void MyInputPanel::saveFocusWidget(QWidget * /*oldFocus*/, QWidget *newFocus)
{ //如果非零,且不是输入面板inputpanel对象的子部件指针就保存
//这里只保存需要输入窗口中的指针
if (newFocus != 0 && !this->isAncestorOf(newFocus)) {
lastFocusedWidget = newFocus;
}
}
void MyInputPanel::buttonClicked(QWidget *w)
{
//property函数返回属性为lylbuttonValue的对应值,这里为每个按键对应的ASCII
//qvariant_cast(T)(value)将输入值value转换为T类型
QChar chr = qvariant_cast<QChar>(w->property("lylbuttonValue"));
testAndsend(chr);
}
//返回主界面焦点处窗口指针
QWidget * MyInputPanel::getFocusedWidget()
{
return lastFocusedWidget;
}
void MyInputPanel::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)//按下时调用buttons函数来判断按键
{
QCursor cursor;
cursor.setShape(Qt::SizeAllCursor);
QApplication::setOverrideCursor(cursor); //暂时使用这种指针
offset = event->globalPos() - pos();//用桌面全局坐标减去窗口坐标,得到需要移动坐标
}
}
void MyInputPanel::mouseMoveEvent(QMouseEvent *event)
{
if(event->buttons() & Qt::LeftButton)//移动中只能用buttons函数
{
QPoint newpoint;
newpoint = event->globalPos() - offset; //减去差值得到新位置
move(newpoint); //移动到新位置
}
}
void MyInputPanel::leaveEvent(QEvent *e)
{
e=e;
this->hide();
}
void MyInputPanel::mouseReleaseEvent(QMouseEvent *)
{
QApplication::restoreOverrideCursor(); //恢复指针形状
}
void MyInputPanel::setbutton(int type)
{
switch(type)
{
case 0:
ui->panelButton_a->setText("a");
ui->panelButton_b->setText("b");
ui->panelButton_c->setText("c");
ui->panelButton_d->setText("d");
ui->panelButton_e->setText("e");
ui->panelButton_f->setText("f");
ui->panelButton_g->setText("g");
ui->panelButton_h->setText("h");
ui->panelButton_i->setText("i");
ui->panelButton_j->setText("j");
ui->panelButton_k->setText("k");
ui->panelButton_l->setText("l");
ui->panelButton_m->setText("m");
ui->panelButton_n->setText("n");
ui->panelButton_o->setText("o");
ui->panelButton_p->setText("p");
ui->panelButton_q->setText("q");
ui->panelButton_r->setText("r");
ui->panelButton_s->setText("s");
ui->panelButton_t->setText("t");
ui->panelButton_u->setText("u");
ui->panelButton_v->setText("v");
ui->panelButton_w->setText("w");
ui->panelButton_x->setText("x");
ui->panelButton_y->setText("y");
ui->panelButton_z->setText("z");
break;
case 1:
ui->panelButton_a->setText("A");
ui->panelButton_b->setText("B");
ui->panelButton_c->setText("C");
ui->panelButton_d->setText("D");
ui->panelButton_e->setText("E");
ui->panelButton_f->setText("F");
ui->panelButton_g->setText("G");
ui->panelButton_h->setText("H");
ui->panelButton_i->setText("I");
ui->panelButton_j->setText("J");
ui->panelButton_k->setText("K");
ui->panelButton_l->setText("L");
ui->panelButton_m->setText("M");
ui->panelButton_n->setText("N");
ui->panelButton_o->setText("O");
ui->panelButton_p->setText("P");
ui->panelButton_q->setText("Q");
ui->panelButton_r->setText("R");
ui->panelButton_s->setText("S");
ui->panelButton_t->setText("T");
ui->panelButton_u->setText("U");
ui->panelButton_v->setText("V");
ui->panelButton_w->setText("W");
ui->panelButton_x->setText("X");
ui->panelButton_y->setText("Y");
ui->panelButton_z->setText("Z");
break;
/*case 2:
ui->panelButton_a->setText("!");
ui->panelButton_b->setText("''");
ui->panelButton_c->setText("#");
ui->panelButton_d->setText("$");
ui->panelButton_e->setText("%");
ui->panelButton_f->setText("(");
ui->panelButton_g->setText(")");
ui->panelButton_h->setText("*");
ui->panelButton_i->setText("+");
ui->panelButton_j->setText(",");
ui->panelButton_k->setText("-");
ui->panelButton_l->setText(".");
ui->panelButton_m->setText("/");
ui->panelButton_n->setText(":");
ui->panelButton_o->setText(";");
ui->panelButton_p->setText("<");
ui->panelButton_q->setText("=");
ui->panelButton_r->setText(">");
ui->panelButton_s->setText("?");
ui->panelButton_t->setText("@");
ui->panelButton_u->setText("_");
ui->panelButton_v->setText("`");
ui->panelButton_w->setText("{");
ui->panelButton_x->setText("|");
ui->panelButton_y->setText("}");
ui->panelButton_z->setText("~");
ui->panelButton_douhao->setText(";");//lzl
break;*/
}
}
void MyInputPanel::keyMapping()
{
signalMapper.setMapping(ui->panelButton_0, ui->panelButton_0);
signalMapper.setMapping(ui->panelButton_1, ui->panelButton_1);
signalMapper.setMapping(ui->panelButton_2, ui->panelButton_2);
signalMapper.setMapping(ui->panelButton_3, ui->panelButton_3);
signalMapper.setMapping(ui->panelButton_4, ui->panelButton_4);
signalMapper.setMapping(ui->panelButton_5, ui->panelButton_5);
signalMapper.setMapping(ui->panelButton_6, ui->panelButton_6);
signalMapper.setMapping(ui->panelButton_7, ui->panelButton_7);
signalMapper.setMapping(ui->panelButton_8, ui->panelButton_8);
signalMapper.setMapping(ui->panelButton_9, ui->panelButton_9);
signalMapper.setMapping(ui->panelButton_a, ui->panelButton_a);
signalMapper.setMapping(ui->panelButton_b, ui->panelButton_b);
signalMapper.setMapping(ui->panelButton_c, ui->panelButton_c);
signalMapper.setMapping(ui->panelButton_d, ui->panelButton_d);
signalMapper.setMapping(ui->panelButton_e, ui->panelButton_e);
signalMapper.setMapping(ui->panelButton_f, ui->panelButton_f);
signalMapper.setMapping(ui->panelButton_g, ui->panelButton_g);
signalMapper.setMapping(ui->panelButton_h, ui->panelButton_h);
signalMapper.setMapping(ui->panelButton_i, ui->panelButton_i);
signalMapper.setMapping(ui->panelButton_j, ui->panelButton_j);
signalMapper.setMapping(ui->panelButton_k, ui->panelButton_k);
signalMapper.setMapping(ui->panelButton_l, ui->panelButton_l);
signalMapper.setMapping(ui->panelButton_m, ui->panelButton_m);
signalMapper.setMapping(ui->panelButton_n, ui->panelButton_n);
signalMapper.setMapping(ui->panelButton_o, ui->panelButton_o);
signalMapper.setMapping(ui->panelButton_p, ui->panelButton_p);
signalMapper.setMapping(ui->panelButton_q, ui->panelButton_q);
signalMapper.setMapping(ui->panelButton_r, ui->panelButton_r);
signalMapper.setMapping(ui->panelButton_s, ui->panelButton_s);
signalMapper.setMapping(ui->panelB
没有合适的资源?快使用搜索试试~ 我知道了~
Linux下Qt精心制作软键盘

共5个文件
h:2个
cpp:2个
ui:1个


温馨提示
在Linux环境下,实现输入框内便捷弹出隐藏、边缘可拖拽、背景透明,科技感极强的软键盘。有详细注释,程序需在mian()函数加上头文件#include"inputMethod/myinputpanelcontext.h" 并在QApplication a(argc, argv);下一行插入: MyInputPanelContext ic; a.setInputContext(&ic); 即可
资源推荐
资源详情
资源评论
















格式:x-zip 资源大小:1.8MB













收起资源包目录







共 5 条
- 1
资源评论

- 那上2021-09-30error: QInputContext: No such file or directory 问题一堆
- 张志杰V2019-05-14???????????????
- 鱼月半2019-05-02不支持中文吗?界面还行,就是略复杂

手写的丶从前
- 粉丝: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 安全风险告知书.doc
- 土压力和土坡稳定.ppt
- 济南市劳动合同法定示范本.doc
- 薄抹灰施工方案-修改版.doc
- 信号处理项目介绍 Python实现基于短时傅里叶变换STFT进行一维数据转二维图像方法的详细项目实例(含模型描述及部分示例代码)
- 第04章-二烯烃.ppt
- 住宅总承包施工合同.doc
- 基础、主体模板工程.doc
- 010-陶瓷锦砖地面.doc
- 小学塑胶运动场工程招标文件.doc
- 唐山某钢铁厂焦化工程焦台模板支撑施工方案(高5.5m).doc
- 员工离职移交确认流程操作简介.ppt
- 第二章工程经济(2).doc
- 【南昌大学】工程招投标与合同管理共111页.ppt
- 安装工程识图算量及工程造价-给排水专业.pdf
- 住宅楼入户防火防盗门制作及安装合同.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
