1.堆栈窗体QStackedWidget:
(1)初始化列表框QListWidget:
QListWidget *list=new QListWidget (this);
list->insertItem(0,tr("Window1"));
list->insertItem(1,tr("Window2"));
list->insertItem(2,tr("Window3"));
(2)新建堆栈窗体QStackedWidget:
QStackedWidget *stack=new QStackedWidget(this);
stack->addWidget(label1);
stack->addWidget(label2);
stack->addWidget(label3);
(3)将标签控件插入堆栈窗体:
QLabel *label1=new QLabel(tr("SHOW1"));
QLabel *label2=new QLabel(tr("SHOW2"));
QLabel *label3=new QLabel(tr("SHOW3"));
(4)对对话框进行布局:
QHBoxLayout *mainLayout =new QHBoxLayout(this);
mainLayout->setMargin(6);
mainLayout->setSpacing(6);
mainLayout->addWidget(list);
mainLayout->addWidget(stack,0,Qt::AlignHCenter);
mainLayout->setStretchFactor(list,1);
mainLayout->setStretchFactor(stack,1);
(5)将QListWidget的信号与堆栈窗体的槽函数连接起来:
connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setcurrentIndex(int)));
时间: 2024-10-08 09:45:27