Important: Please read the Qt Code of Conduct -

How to steal focus on simple mouse click at an empty space of the window?

  • So i have a spinbox which is connected with editingfinished..
    so i want the void editing finished to be called if you click with the mouse at an empty space at that window.. How to accomplish that?

  • If I understand you correctly, you can inherit from QWidget and override the "event": :

    class MyClass: public QWidget {
    void mousePressEvent(QMouseEvent *event) {
    // some code

  • In addition to the above code you need to emit a signal inside mousePressEvent() like

    @void MyClass::mousePressEvent(QMouseEvent *event)

    if (event->button() == Qt::LeftButton)
        emit clicked();


    where clicked() is a signal declared in .h file eg

    @class MyClass : public QWidget
    //some declaration ... ...

    void clicked();

    Ui::MyClass *ui;


    and you need to connect signal & slots like


Log in to reply