Considerations for event-triggered scenarios with Qlineedit in QT forms

Source: Internet
Author: User

When you click OK, Cancel, and other buttons on the form, the slot function of the button is preceded by the Qlineedit editingfinished () signal

This can lead to many problems, such as clicking the Close button, the form's closeevent is rewritten to be hidden, then the Qlineedit focusoutevent event triggers the editingfinished () signal, This signal connection slot function is used to check the legality of Qlineedit, the law pop-up hint form, so that Qlineedit focusoutevent will be triggered ... The back is the infinite loop (this time you cry to t_t)

Solution: Customize a Qlineedit, and override Focusoutevent

public QLineEdit{    Q_OBJECTpublic:    MyLineEdit0) : QLineEdit(parent) {}    ~MyLineEdit(){}protected:    virtualvoidfocusOutEvent(QFocusEvent * e)    {        if (e->reason() == Qt::ActiveWindowFocusReason)        {            return;        }        else        {            QLineEdit::focusOutEvent(e);        }    }};

Considerations for event-triggered scenarios with Qlineedit in QT forms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.