• 2358阅读
  • 1回复

[提问]qt 4.8.5 程序运行时随机出错 [复制链接]

上一主题 下一主题
离线c65193145
 

只看楼主 倒序阅读 楼主  发表于: 2018-01-18
我的一个应用由于没有鼠标,在界面上的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);";}}
离线never_forget

只看该作者 1楼 发表于: 2018-01-22
这个不是很好看,(也许我不够强),不过你试过用 Tab 顺序来完成焦点切换不 ?
快速回复
限100 字节
 
上一个 下一个