Results 1 to 8 of 8

Thread: QLineEdit

  1. #1
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default QLineEdit

    Hello

    I have a QLineedit with mask and qvalidator (subclassed)

    How can i prevent to move away the focus if the input isn't match the mask or validator ?

    Because neither mask nor qvalidator don't prevent to move away focus from QLineEdit.

    And editingfinished isn't work because :

    "void QLineEdit::editingFinished()

    This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable."

    void MainWindow:n_lineEdit_editingFinished()
    {
    if (ui->lineEdit->text() != "1111") ui->lineEdit->setFocus();
    }


    So mask (an validator) doesn't work together with editingFinsihed signal.

    thank you Attila

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit

    You should be able to detect the focus change by implementing the focusOutEvent() handler.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLineEdit

    Thank you Anda_skoa

    But i'm a beginner
    Could you give me a short sample

    i have tried this , but the program crashed

    bool MainWindow::eventFilter(QObject *filterObj, QEvent *event)
    {
    if (filterObj == ui->lineEdit ) {
    if(event->type() == QEvent::FocusOut) {
    if (ui->lineEdit->text() != "1111") { ui->lineEdit->setFocus();};
    return true;
    };
    };
    return false;
    }








    thank you Attila

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit

    Have you checked where it crashes?

    Alternatively to an event filter you could also try reimplementing QWidget::focusOutEvent(), i.e. derive a new class from QLineEdit and overwrite the virtual method.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLineEdit

    Thnak you for your answer

    the problem is at setFocus()

    and if i reimplement the focusOutEvent - the result is the same.

    Attila

  6. #6
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLineEdit

    Similar problem like here :

    https://forum.qt.io/topic/11423/forb...-a-qlineedit/6

    Attila

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit

    You could try calling setFocus() delayed since it is a slot

    Qt Code:
    1. QMetaObject::invokeMethod(lineEdit, "setFocus", Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  8. #8
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLineEdit

    thank you

    but unfortunatelly i doesn't help me - the cursor bounce from one control to another and back again ....

    Thank you your kindness
    Attila

Similar Threads

  1. Replies: 2
    Last Post: 9th July 2016, 10:59
  2. Replies: 1
    Last Post: 12th October 2010, 22:20
  3. help with QLineEdit
    By benlyboy in forum Newbie
    Replies: 2
    Last Post: 18th February 2010, 01:39
  4. QLineEdit
    By rick_st3 in forum Newbie
    Replies: 1
    Last Post: 14th June 2008, 09:05
  5. Tab QLineEdit
    By jaca in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2008, 13:01

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.