QStackedWidget实现左侧列表与右侧控件关联

来源:互联网 发布:linux下启动tomcat服务 编辑:程序博客网 时间:2024/06/13 17:38

实现效果:
这里写图片描述

源码:

    setWindowTitle(tr("StackedWidget"));    list =new QListWidget(this);    list->insertItem(0,tr("Window1"));    list->insertItem(1,tr("Window2"));    list->insertItem(2,tr("Window3"));    label1 =new QLabel(tr("WindowTest1"));    label1->setStyleSheet("background-color:red");    label2 =new QLabel(tr("WindowTest2"));    label2->setStyleSheet("background-color:green");    label3 =new QLabel(tr("WindowTest3"));    stack =new QStackedWidget(this);    stack->setStyleSheet("background-color:yellow");    stack->addWidget(label1);    stack->addWidget(label2);    stack->addWidget(label3);    QHBoxLayout *mainLayout =new QHBoxLayout(this);    mainLayout->setMargin(5);    mainLayout->setSpacing(5);    mainLayout->addWidget(list);    mainLayout->addWidget(stack,0,Qt::AlignHCenter);    mainLayout->setStretchFactor(list,1);    mainLayout->setStretchFactor(stack,4);    connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));
阅读全文
0 0
原创粉丝点击