2013-08-22 28 views

回答

0

你需要使用一个QProcess,并重新实现方法QLineEdit::focusInEventQLineEdit::focusOutEvent。尝试实现一个类从QLineEdit继承这样的:

#include <QLineEdit> 
#include <QProcess> 

class MyLineEdit: public QLineEdit 
{ 
public: 
    MyLineEdit(QWidget * parent = 0): QLineEdit(parent) 
    { 
     process_ = new QProcess(); 
    } 

protected: 
    void focusInEvent(QFocusEvent * e) 
    { 
     QLineEdit::focusInEvent(e); 
     process_->start("start C:\\osk.exe"); 
    } 
    void focusOutEvent(QFocusEvent * e) 
    { 
     QLineEdit::focusOutEvent(e); 
     process_->kill(); 
    } 

private: 
    QProcess * process_; 
} 

(当然这个osk.exe的确切地址替换C:\\osk.exe)。

然后只需使用MyLineEdit而不是QLineEdit,它应该工作。我不知道如何隐藏或最小化这个过程,所以我决定杀了它,并在必要时重新启动它;-)