tags:

views:

33

answers:

1

I have a modal QDialog, that on the click of a button slides a modeless child QDialog out from underneath it. The problem I have is that the child stays on top of its parent during the animation.

I think I could get away with applying a mask over the portion of the child that overlaps the parent, but it feels like I'm missing a more obvious way of just placing the child under the parent.

I'm using Qt 4.5. Here's some sample code:

void MainWindow::on_myMenu_triggered()
{
    parentDlg = new QDialog(this);
    parentDlg->setFixedSize(250, 250);
    parentDlg->setModal(true);
    parentDlg->show();

    childDlg = new QDialog(parentDlg);
    childDlg->setFixedSize(150, 150);
    childDlg->show();
    QTimeLine* timeLine = new QTimeLine(1000, this);
    connect(timeLine, SIGNAL(valueChanged(qreal)), this,  SLOT(childDlgStepChanged(qreal)));
    timeLine->start();  
}

void MainWindow::childDlgStepChanged(qreal)
{
    int parentX = parentDlg->frameGeometry().x();
    int parentY = parentDlg->geometry().y();

    // Move the child dialog to the left of its parent.
    childDlg->move(parentX - 150 * step, parentY);
}

Thanks in advance.

A: 

Child widgets are always rendered over the parent so you would have to break that relationship in order to achieve the affect you are looking for directly. Then you could use raise() or lower() if both dialogs had the same parent.

Arnold Spence
Thanks, I hadn't considered reparenting. I hit problems when I tried reparenting the animated child dialog back to the parent dialog at the end of the timeline, and ended up just creating a new child dialog and destroying the child dialog that was used for the animation.
Robin