[Solved] How to handle position changed of QWidget?



  • 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.



  • 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;;
    

    }

    @



  • Thanks, it worked


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.