PDA

View Full Version : QDialog and focus



Alundra
27th November 2014, 20:19
Hi,
I have a QDialog with different layout, inside them I have several QLineEdit. the QDialog is modal to force to do action in dialog.
The problem is I need to use editingFinished() to update other value but if I click on QDialog I have no leaveFocus so that's not called.
If I press enter I have the QDialog closed without the editingFinished() called too.
How solve this problem ?
Thanks for the help

Alundra
28th November 2014, 03:55
I tried that code but doesn't works I have the dialog closed when enter pressed :


bool CColorPickerDialog::event( QEvent* event )
{
if( event->type() == QEvent::KeyPress )
{
if( m_HexEdit->hasFocus() )
return true;
}
return QDialog::event( event );
}

That only works if I don't clear focus of the QLineEdit but I do :


void CColorPickerDialog::HexEditingFinished()
{
m_RadialColorPickerWidget->SetColor( QColor( QString( "#%1" ).arg( m_HexEdit->text() ) ) );
m_HexEdit->clearFocus();
}

Having the bypass of default button working and lost focus of widged when clicking on QDialog still a mystery.
The problem is since that closes the color picker widget I don't have any preview of the value I wrote on the hex line edit.

Alundra
30th November 2014, 21:00
In reality I need to find a way to bypass the default button on each widget because they need the enter key but actually not found, if someone has idea to achieve that ?

EDIT :
Finally I use the easy method, I bypass enter to only accept esc :


void CColorPickerDialog::keyPressEvent( QKeyEvent* e )
{
if( ( e->key() != Qt::Key_Enter ) && ( e->key() != Qt::Key_Return ) )
QDialog::keyPressEvent( e );
}