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. [Solved] How to handle position changed of QWidget?

[Solved] How to handle position changed of QWidget?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 7.3k Views
  • 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.
  • F Offline
    F Offline
    fifth
    wrote on last edited by
    #1

    I'm quite new to Qt.
    I'm looking for a way to handle position changed, really like onPosChanged handler. I found nothing in SDK.
    Anyone can give me a hint?
    Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      anselmolsm
      wrote on last edited by
      #2

      In general lines, you can reimplement the "QWidget::moveEvent":http://doc.qt.nokia.com/4.7/qwidget.html#moveEvent method:

      @
      class MyWidget : public QWidget
      {
      protected:
      void moveEvent ( QMoveEvent * event ) {
      qDebug() << "moved!";
      }
      };

      int main( int argc, char **argv )
      {
      QApplication app( argc, argv );

      MyWidget w;
      w.show();
      
      return app.exec&#40;&#41;;
      

      }
      @

      or "install an eventFilter":http://doc.qt.nokia.com/4.7/qobject.html#installEventFilterthat which handles QEvent::Move:

      @
      class FilterObj : public QObject
      {
      protected:
      bool eventFilter(QObject *obj, QEvent *event) {
      if (event->type() == QEvent::Move) {
      qDebug() << "moved!";
      return true;
      } else {
      // standard event processing
      return QObject::eventFilter(obj, event);
      }
      }
      };

      int main( int argc, char **argv )
      {
      QApplication app( argc, argv );

      QWidget w;
      FilterObj obj;
      w.installEventFilter(&obj);
      w.show();
      
      return app.exec(&#41;;
      

      }

      @

      Anselmo L. S. Melo (anselmolsm)

      1 Reply Last reply
      2
      • F Offline
        F Offline
        fifth
        wrote on last edited by
        #3

        Thanks, it worked

        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