开发者

How to hide a QWidget under its parent?

开发者 https://www.devze.com 2023-01-19 10:58 出处:网络
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 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 s开发者_如何转开发ample 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号