Qt中左侧列表与右侧窗口关联

    xiaoxiao2021-04-14  76

    //左边列表选项与右边窗体关联 QListWidget *list =new QListWidget(this); list->insertItem(0,tr("Window1")); list->insertItem(1,tr("Window2")); QLabel *label1 =new QLabel(tr("WindowTest1")); QLabel *label2 =new QLabel(tr("WindowTest2")); QStackedWidget *stack =new QStackedWidget(this); stack->addWidget(label1); stack->addWidget(label2); QHBoxLayout *mainLayout =new QHBoxLayout(this); mainLayout->setMargin(5); mainLayout->setSpacing(5); mainLayout->addWidget(list); mainLayout->addWidget(stack,0,Qt::AlignHCenter); //设置左侧list所占的宽度 mainLayout->setStretchFactor(list,1); mainLayout->setStretchFactor(stack,3); connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int)));

    效果图:

    转载请注明原文地址: https://ju.6miu.com/read-670150.html

    最新回复(0)