2013-08-22 31 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,它應該工作。我不知道如何隱藏或最小化這個過程,所以我決定殺了它,並在必要時重新啓動它;-)