Unsolved hasFocus() ??
-
how to check a lineEdit or a pushButton has focus ? ();
i used ui->lineEdit_username->hasFocus(), but it does'n work .
someone cans tell me why ? -
@Duy-Khang said in hasFocus() ??:
but it does'n work .
Well, I would imagine it does work, else others would complain?! How does your situation compare to, say, https://stackoverflow.com/questions/46702487/how-can-i-get-current-focused-qlineedit-in-qt ?
-
@JonB said in hasFocus() ??:
Well, I would imagine it does work, else others would complain?! How does your situation compare to, say
not like that. suppuse :
ui->lineEdit_username->setFocus();
if(ui->lineEdit_username->hasFocus())
{
ui->lineEdit_username->setStyleSheet("color : red"); // it still doesn't work ?
} -
@Duy-Khang
Please just put inif(ui->lineEdit_username->hasFocus()) qDebug() << "Yes has focus";
-
it stil does not work !
-
Hi
Useing code to check for fucus will work poorly if used in constructor and code must be run every time
focus shifts so it's easier to do with stylesheet alone.QLineEdit:focus { color:red; }