[Interest] Glueing widgets together

Tony Rietwyk tony at rightsoft.com.au
Sat Jun 29 06:09:27 CEST 2013


> Sent: Friday, 28 June 2013 10:48 PM
> 
> On 6/28/13 10:54 AM, Tony Rietwyk wrote:
> > Hi Sensei,
> >
> > I have a master dialog with a slave dialog attached to one border.
> > This was done using eventFilter in the slave to listen to the master
> > Move and Resize events - not MouseMove.  It's only 10 lines of code,
> > works well and there is no jerkiness.  It put the code in the slave,
> > since it can be attached to many different dialogs in my app.
> >
> > The same code should work for peer dialogs - but you must be careful
> > to prevent recursion by settings flags in the other dialog before
> > moving it so it doesn't try to move the first one.  The recursion
> > could cause the delays and high CPU usage.
> >
> > Can you show the code that isn't working?
> 
> Sure!
> 
> My code is as follows. It works, in the sense that, as I said, the
follower
> moves to the right position. However, I can move the main window and the
> follower, visibly after a while, pops out where it should be. It's a very
> annoying visual glitch.
> 
> I've tried two codes, one with overriding the event, one with a filter.
> 
> =====================
> // The follower
> void SubContainer::followActivated(QMoveEvent *event) {
>      qWarning(">> MOVE IT!");
> 
>      // Move the follower where the options_ button is
>      QPoint local  = options_->pos();
>      QPoint global = mapToGlobal(local);
> 
>      global.setX(global.x() + 0*options_->width());
>      global.setY(global.y() + options_->height());
> 
>      qWarning("show on (%d, %d) (%d, %d)", local.x(), local.y(),
global.x(),
> global.y());
> 
>      follower_->move(global);
> }
> 
> 
> 
> // Move event handler
> void MainWindow::moveEvent(QMoveEvent *event) {
>      qWarning("I LIKE TO MOVE IT");
>      container_->getSubContainer()->followActivated(event);
> }
> =====================
> 
> 
> 
> I've tried also (of course not at the same time as the above code) to
install an
> event filter, however, and the results are the same:
> 
> 
> =====================
> // Event filtering
> bool SubContainer::eventFilter(QObject *object, QEvent *event)
> {
>      // The target_ variable contains the MainWindow object
>      if ((object == target_) && (event->type() == QEvent::Move))
>      {
>          qWarning("=== filtering object %p / target %p", object, target_);
>          followActivated(NULL);
>      }
>      return true;
> }
> =====================
> 
> There's always a delay in moving the MainWindow and the follower moving
> to its right position.
> 
> I'm puzzled. How did you succeed in having these two dialogs move
> simultaneously? Can you post an excerpt?
> 
> Thanks & Cheers!

Hi Sensei, 

My code is just: 

bool Slave::eventFilter(QObject *obj, QEvent *ev)
{
  if (obj == Master)
     move( Master->frameGeometry().left() + Master->frameGeometry().width(),
Master->frameGeometry().top() );

  return Ancestor::eventFilter(obj, ev);
}

Note that I do not return true - since I want the move to be handled by the
Master as normal.  

The Master is the parent of the Slave, and the Slave is created with window
flag Qt::Tool.  

Hope that helps, 

Tony.





More information about the Interest mailing list