How can I identify which QLineEdit has the current focus in qt?
To set the focus for QLinEdit I have tried:
ui->linedit->setfocus();
but it also not working for me. How can I solve these two?
解决方案
To identify which focused Widget (QlineEdit or any QWidget), you need to get all your current widget children, cast each to QLineEdit, and check which one has focus, sample code:
QList mylineEdits = this->findChildren();
QListIterator it(mylineEdits); // iterate through the list of widgets
QWidget *lineEditField;
while (it.hasNext()) {
lineEditField = it.next(); // take each widget in the list
if(QLineEdit *lineE = qobject_cast(lineEditField)) { // check if iterated widget is of type QLineEdit
//
if (lineE->hasFocus())
{
// this has the focus ...
}
}
}
Second issue, setting focus on QWidget, already answered in this Post: