Qt中堆栈窗口

 QListWidget* pList = new QListWidget(this);
    pList->insertItem(0, QStringLiteral("window1"));
    pList->insertItem(1, QStringLiteral("window2"));
    pList->insertItem(2, QStringLiteral("window3"));

    QLabel* pLabel1 = new QLabel(QStringLiteral("label1"));
    QLabel* pLabel2 = new QLabel(QStringLiteral("label2"));
    QLabel* pLabel3 = new QLabel(QStringLiteral("label3"));

    QStackedWidget* pStack = new QStackedWidget(this);
    pStack->addWidget(pLabel1);
    pStack->addWidget(pLabel2);
    pStack->addWidget(pLabel3);

    QHBoxLayout* pLayout = new QHBoxLayout(this);
    pLayout->setMargin(5);      //设置对话框边距为5
    pLayout->setSpacing(5);     //设置控件之间的边距为5
    pLayout->addWidget(pList);
    pLayout->addWidget(pStack);

    connect(pList, SIGNAL(currentRowChanged(int)), pStack, SLOT(setCurrentIndex(int))); //切换listitem,堆栈窗口切换

你可能感兴趣的:(Qt中堆栈窗口)