PDA

View Full Version : QLineEdit setFocus



bunjee
24th April 2008, 17:00
Hey there, I'm using that call to set the focus on my QLineEdit widget.


/* virtual */ void ZeConversationWidget::showEvent(QShowEvent * event)
{
mConversationInput->getMessageInput().setFocus();
}

I don't get any focus.
But when I do resize the window, strangely enough the focus is suddenly set on that QLineEdit, and it works.

I'm using 4.4 release candidate.

Has anyone got an idea?

^NyAw^
24th April 2008, 17:12
Hi,

From QWidget doc:

Be aware that if the widget is hidden, it will not accept focus until it is shown.

So, if the widget is not shown yet, it don't will get the focus.

aamer4yu
24th April 2008, 17:20
For such things use singleShot to set the data values etc, related to showing of widgets etc


QTimer::singleShot(0,this,initialize());
MyWindow::initialize()
{
mConversationInput->getMessageInput().setFocus();
}



Hope this helps :)

bunjee
24th April 2008, 17:21
I did a check with isVisible :


/* virtual */ void ZeConversationWidget::showEvent(QShowEvent * event)
{
if (mConversationInput->getMessageInput().isVisible())
{
// My code gets here
std::cout << "Hello\n";
mConversationInput->getMessageInput().setFocus();
}
}

bunjee
24th April 2008, 17:22
For such things use singleShot to set the data values etc, related to showing of widgets etc


Hope this helps :)

Tried that one too, no success. I need to resize my window to get focus.
I think it might be a QT 4.4 bug.