qt 4.8.5 程序运行时随机出错

weixin_38079044 2019-09-19 12:40:05
我的一个应用由于没有鼠标,在界面上的pushbutton qlineedit 等用左右键切换,重载了qlineedit类,但反复切换一段时间后,当光标进行qlineedit 中后,无法在把焦点切出来了。centos5的控制台没有报错信息,其他线程也正常工作,就是重载了qlineedit类无法接收到key event了。也不是一直错,跑一段时间后不好用。求大家帮我看看#ifndef DEMOEDIT_H#define DEMOEDIT_H#include<QLineEdit>#include<QKeyEvent>class DemoEdit : public QLineEdit{ public:    DemoEdit(QWidget *p=NULL); protected:      virtual void keyPressEvent(QKeyEvent *e);};#endif // DEMOEDIT_H#include "demoedit.h"#include<QDebug>DemoEdit::DemoEdit(QWidget * p):QLineEdit(p){}void DemoEdit::keyPressEvent(QKeyEvent *e){int  key=e->key();if(key==Qt::Key_Right){    focusNextChild();    e->accept();    qDebug()<<"focusNextChild";}else if(key==Qt::Key_Down){    focusNextChild();    qDebug()<<"focusPreviousChild";    e->accept();}else if(key==Qt::Key_Left){    focusPreviousChild();    qDebug()<<"focusPreviousChild";    e->accept();}else if(key==Qt::Key_Up){    focusPreviousChild();    qDebug()<<"focusPreviousChild";    e->accept();}else if(key==Qt::Key_Escape)//Qt:Key_Escape{    this->setText("");    e->accept();}else if(key==Qt::Key_F12)//Qt:Key_Escape{    this->setText((this->text()+"."));    e->accept();}else{    QLineEdit::keyPressEvent(e);   qDebug()<<" QLineEdit::keyPressEvent(e);";}}
...全文
20 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38108514 2019-09-19
  • 打赏
  • 举报
回复
这个不是很好看,(也许我不够强),不过你试过用 Tab 顺序来完成焦点切换不 ?

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧