Qt 之层叠QWidget,使用QStackedLayout

 //底层widget
    QWidget* wd1 = new QWidget();
    QHBoxLayout* hbox = new QHBoxLayout(wd1);
    QWidget* wd1Left = new QWidget();
    wd1Left->setStyleSheet("background-color: rgb(0, 200, 0);");
    QWidget* wd1Right = new QWidget();
    wd1Right->setStyleSheet("background-color: rgb(0, 0, 10);");
    hbox->addWidget(wd1Left);
    hbox->addWidget(wd1Right);
    wd1->setLayout(hbox);

    //顶层widget
    QWidget* wd2 = new QWidget();
    QHBoxLayout* hbox2 = new QHBoxLayout(wd2);
    QWidget* wd2Left = new QWidget();
    wd2Left->setStyleSheet("background-color: rgb(10, 50, 20,0);");
    QWidget* wd2Center = new QWidget();
    wd2Center->setStyleSheet("background-color: rgb(200, 0, 0, 80);");
    QWidget* wd2Right = new QWidget();
    wd2Right->setStyleSheet("background-color: rgb(60, 128, 10,0);");
    hbox2->addWidget(wd2Left);
    hbox2->addWidget(wd2Center);
    hbox2->addWidget(wd2Right);
    wd2->setLayout(hbox2);

    //
    QStackedLayout * sBoxLayout = new QStackedLayout();
    sBoxLayout->setStackingMode(QStackedLayout::StackAll);
    sBoxLayout->addWidget(wd1);
    sBoxLayout->addWidget(wd2);
    wd1->stackUnder(wd2);

    //
    QVBoxLayout* layoutMain = new QVBoxLayout();
    layoutMain->addLayout(sBoxLayout);

    this->centralWidget()->setLayout(layoutMain);

Qt 之层叠QWidget,使用QStackedLayout

上一篇:QT组件之间的关联(伙伴关系)和Tab键的顺序调整,代码实现


下一篇:MySQL安装以及与Navicat建立连接出现1251错误