Details
-
Bug
-
Resolution: Out of scope
-
P2: Important
-
4.7.0
-
Windows XP
Description
Hi,
In Qt4.7.0 QWidget::setFocus() looks like this:
void QWidget::setFocus(Qt::FocusReason reason)
{
if (!isEnabled())
return;
QWidget *f = this;
while (f->d_func()>extra && f>d_func()>extra>focus_proxy)
f = f->d_func()>extra>focus_proxy;
...
But if the focus proxy widget is disabled, then it can't make use of the focus. Wouldn't it be better to place the check for enabled after the while loop?
if ( ! f->isEnabled() )
return;
Example program: 3 Labels and Lineedits.
Clicking on the disabled lineedit won't set the focus, but clicking on the label next to it does. The cursor will start blinking in the disabled lineedit.
#include <QApplication>
#include <QLabel>
#include <QLineEdit>
#include <QGridLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
QGridLayout* pLayout = new QGridLayout(&w);
QLabel* pLabel1 = new QLabel( "Label 1" );
QLineEdit* pLineEdit1 = new QLineEdit();
pLayout->addWidget( pLabel1, 0, 0 );
pLayout->addWidget( pLineEdit1, 0, 1 );
QLabel* pLabel2 = new QLabel( "Label 2" );
QLineEdit* pLineEdit2 = new QLineEdit();
pLayout->addWidget( pLabel2, 1, 0 );
pLayout->addWidget( pLineEdit2, 1, 1 );
QLabel* pLabel3 = new QLabel( "Label 3" );
QLineEdit* pLineEdit3 = new QLineEdit();
pLayout->addWidget( pLabel3, 2, 0 );
pLayout->addWidget( pLineEdit3, 2, 1 );
pLabel1->setFocusPolicy( Qt::ClickFocus );
pLabel2->setFocusPolicy( Qt::ClickFocus );
pLabel3->setFocusPolicy( Qt::ClickFocus );
pLabel1->setFocusProxy( pLineEdit1 );
pLabel2->setFocusProxy( pLineEdit2 );
pLabel3->setFocusProxy( pLineEdit3 );
pLineEdit2->setEnabled(false);
w.show();
return a.exec();
}
Best regards,
Joachim