Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top