Results 1 to 3 of 3

Thread: QDialog and focus

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QDialog and focus

    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

  2. #2
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog and focus

    I tried that code but doesn't works I have the dialog closed when enter pressed :
    Qt Code:
    1. bool CColorPickerDialog::event( QEvent* event )
    2. {
    3. if( event->type() == QEvent::KeyPress )
    4. {
    5. if( m_HexEdit->hasFocus() )
    6. return true;
    7. }
    8. return QDialog::event( event );
    9. }
    To copy to clipboard, switch view to plain text mode 
    That only works if I don't clear focus of the QLineEdit but I do :
    Qt Code:
    1. void CColorPickerDialog::HexEditingFinished()
    2. {
    3. m_RadialColorPickerWidget->SetColor( QColor( QString( "#%1" ).arg( m_HexEdit->text() ) ) );
    4. m_HexEdit->clearFocus();
    5. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by Alundra; 28th November 2014 at 03:11.

  3. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog and focus

    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 :
    Qt Code:
    1. void CColorPickerDialog::keyPressEvent( QKeyEvent* e )
    2. {
    3. if( ( e->key() != Qt::Key_Enter ) && ( e->key() != Qt::Key_Return ) )
    4. QDialog::keyPressEvent( e );
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Alundra; 30th November 2014 at 20:34.

Similar Threads

  1. Replies: 9
    Last Post: 25th March 2011, 21:22
  2. QDialog.exec() exiting without calling QDialog::accept()
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2011, 11:35
  3. Focus or update problem in modal QDialog
    By AlHadr in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2010, 21:32
  4. QDialog derived and focus problem
    By elm66 in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2008, 21:52
  5. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.