Qt5 layout management (2)

Source: Internet
Author: User

1. Stack form qstackedwidget:

(1) initialize the ListBox qlistwidget:

QListWidget *list=new QListWidget (this);
    list->insertItem(0,tr("Window1"));
    list->insertItem(1,tr("Window2"));
    list->insertItem(2,tr("Window3"));

(2) create a stack form qstackedwidget:

 QStackedWidget *stack=new QStackedWidget(this);
    stack->addWidget(label1);
      stack->addWidget(label2);
        stack->addWidget(label3);

(3) Insert the tag control into the stack form:

QLabel *label1=new QLabel(tr("SHOW1"));
     QLabel *label2=new QLabel(tr("SHOW2"));
     QLabel *label3=new QLabel(tr("SHOW3"));

(4) layout the dialog box:

 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) connect the qlistwidget signal with the slot function of the stack form:

 connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setcurrentIndex(int)));


Qt5 layout management (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.