Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to steal focus on simple mouse click at an empty space of the window?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • podsvirovP Offline
      podsvirovP Offline
      podsvirov
      wrote on last edited by
      #2

      If I understand you correctly, you can inherit from QWidget and override the "event":http://qt-project.org/doc/qwidget.html#mousePressEvent :

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        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
        {
        Q_OBJECT
        public:
        //some declaration ... ...

        signals:
        void clicked();

        private:
        Ui::MyClass *ui;

        };@

        and you need to connect signal & slots like

        @connect(this,SIGNAL(clicked()),SLOT(editingfinished()));@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved