I'm having trouble selecting all the text in a QLineEdit control inside an eventFilter.
In a QDialog, I want to select all text in a QLineEdit control when a user tabs into it. My eventFilter recognizes the control but doesn't select.
{
if ( pEvent
->type
() == QEvent::FocusIn ) {
if ( pObj == ui.ipAddrEdt ) // ipAddrEdt has focus at this point
{
ui.ipAddrEdt->selectAll();
ui.ipAddrEdt->setCursorPosition( 0 );
return true;
}
...
bool AddMainPage::eventFilter( QObject* pObj, QEvent* pEvent )
{
if ( pEvent->type() == QEvent::FocusIn )
{
if ( pObj == ui.ipAddrEdt ) // ipAddrEdt has focus at this point
{
ui.ipAddrEdt->selectAll();
ui.ipAddrEdt->setCursorPosition( 0 );
return true;
}
...
To copy to clipboard, switch view to plain text mode
I'm not sure that I'm going about this in the correct way either. I don't want to selectAll() when the user uses the mouse to click into the control, only when it's tabbed into. I know that I'm dealing with 2 different events here; QEvent::FocusIn and QEvent::KeyPress.
Does anyone have any suggestions on how best to handle this situation?
Bookmarks