13.QT多窗口切换list

 1 Dialog::Dialog(QWidget *parent) :
 2     QDialog(parent),
 3     ui(new Ui::Dialog)
 4 {
 5     ui->setupUi(this);
 6 
 7     list = new QListWidget(this);
 8     list->insertItem(0,"win1");
 9     list->insertItem(1,"win2");
10     list->insertItem(2,"win3");
11 
12     //用于传给stack
13     label1=new QLabel("win1");
14     label2=new QLabel("win2");
15     label3=new QLabel("win3");
16 
17     //创建新的栈
18     stack = new QStackedWidget(this);
19     //添加
20     stack->addWidget(label1);
21     stack->addWidget(label2);
22     stack->addWidget(label3);
23     //创建HBoxLayout
24     QHBoxLayout *qhl = new QHBoxLayout(this);
25     qhl->setMargin(10);//设置边框
26     qhl->setSpacing(5);//设置间隔
27     qhl->addWidget(list);//加入list
28     qhl->addWidget(stack,0,Qt::AlignCenter);//加入stack
29     qhl->setStretchFactor(stack,1);//设置可拓展性,是否能随着窗口的变化大小发生相应的变化
30 
31     connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));
32 }
原文地址:https://www.cnblogs.com/xiaochi/p/8746304.html