[Interest] Glueing widgets together
Sensei
senseiwa at gmail.com
Fri Jun 28 14:48:06 CEST 2013
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!
More information about the Interest
mailing list