QLineEdit* pEditor = new QLineEdit(m_strText);
pEditor->resize(.......);
pEditor->move(........);
scene()->addWidget(pEditor);
pEditor->setFocus();
注意紅色字體的倆個語句的順序。若反序,就會出現【QLineEdit怎樣實現獲得焦點時即可輸入】的問題,因為Focus了之后馬上又Out 了,導致不可輸入。
其實也很好理解:一定要放在setLayout的后面,否則還沒有真正顯示,又怎么能設置焦點呢?
-----------------------------------------------------------
另外還有:
this->activateWindow();
pass1_edit->setFocusPolicy(Qt::StrongFocus);
在需要的時候,也要設置
