On 6/13/13 8:38 PM, Andre Somers wrote: > While Bill is right, there is another way that allows you to do this > without changing the main window for it: event filters. That will allow > you to keep all the code you need for this in one place, in the widget > that you want to make move. > > What I'd do, is give that widget a constructor argument with a pointer > to the widget to follow around. Using QWidget::window, you find out what > the window is the widget to be followed lives in. Install an event > filter on that window-widget. If you use scrollable views somewhere, > you'll need to iterate up yourself, to install the event filter for > every widget in between too. > In your widget-that-follows, reimplement the eventFilter(QObject*, > QEvent*) method, and look for move and resize events. If you get these, > you again take the geometry of the widget-to-follow, and use the > mapToGlobal function of the widget-to-follow to get the global > coordinates. Then, re-position your widget-that-follows to those > coordinates.
Dear all, I've tried to reimplement the moveEvent as suggested, just printing a string, but it's slow: I see a noticeable delay between the movement and the output string. For the filter, Andre, I've probably misunderstood how to use it. Let's say I have a window and a follower. In the window I have to install the event filter, giving it as parameter the follower widget. In the follower, I need to reimplement the eventFilter. Something in my code is wrong, though... Here's what I did: mywidget::mywidget(QWidget *parent, Qt::WindowFlags flags, QWidget *follower) : QWidget(parent, flags) { // Follow a target window target_ = follower; } bool mywidget::eventFilter(QObject *object, QEvent *event) { if ((object == target_) && (event->type() == QEvent::Move)) { qWarning("MOVE IT"); } return false; } In the main window: installEventFilter(mywidgetInstance); However, the "MOVE IT" is never seen :( _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest