Simple implementation of qradiobutton grouping Without Borders

Source: Internet
Author: User

I recently used QT + vs2008 to build a project that involves a comprehensive evaluation table. To put it bluntly, it is a bit like a questionnaire survey-there are several options for each question in many questions.

Initially, I planned to use a drop-down box with all the options in each box. However, I thought this method was not intuitive and user-friendly, and added a step of user drop-down operations.

So I decided to replace the single-choice button, which is called qradiobutton in QT. The first half of the interface is a question, and the last half is a small round hole of a line, directly:

I was excited to compile and run it immediately. It was a bit of a crash, and there was only one button on the interface at the same time.

Of course, after you have calmed down, you will know the reason: You have not grouped these buttons.

Grouping: First of all, we intuitively think of using qgroupbox. I forgot to explain it before. In fact, the name of the control class in QT is similar to that in MFC, it's just a long time to discover that the former is easier to develop GUI applications through pure code.

Immediately configure a qgroupbox for the four dots in each row. The qhboxlayout control is used for horizontal layout, and the padding and other attributes of the Child control can be set through the method.

Compilation and operation showed that each row had a group frame. It was obviously not beautiful enough to check it online.

Experts, such as cloud, tried to change the attributes of qgroupbox one by one, and all ended in failure.

Finally, we adopted a simple and tall method: replacing qgroupbox with qwidget, which is competent for work and environmentally friendly without borders.

Simply find and replace it for a moment to achieve the goal. The complete implementation code of the above eleven groups is displayed below, which is clumsy. After reading the code, I hope to improve the code size and complexity!

Declare the required variable in "XXX. H". Here only the radio button section is provided:

QRadioButton *jradio11;QRadioButton *jradio12;QRadioButton *jradio13;QRadioButton *jradio14;QRadioButton *jradio21;QRadioButton *jradio22;QRadioButton *jradio23;QRadioButton *jradio24;QRadioButton *jradio31;QRadioButton *jradio32;QRadioButton *jradio33;QRadioButton *jradio34;QRadioButton *jradio41;QRadioButton *jradio42;QRadioButton *jradio43;QRadioButton *jradio44;QRadioButton *jradio51;QRadioButton *jradio52;QRadioButton *jradio53;QRadioButton *jradio54;QWidget *jiaxiangG1;QWidget *jiaxiangG2;QWidget *jiaxiangG3;QWidget *jiaxiangG4;QWidget *jiaxiangG5;QHBoxLayout *jiaxiangH1;QHBoxLayout *jiaxiangH2;QHBoxLayout *jiaxiangH3;QHBoxLayout *jiaxiangH4;QHBoxLayout *jiaxiangH5;

In "XXX. cpp", implement:

jradio11 = new QRadioButton(this);jradio12 = new QRadioButton(this);jradio13 = new QRadioButton(this);jradio14 = new QRadioButton(this);jradio21 = new QRadioButton(this);jradio22 = new QRadioButton(this);jradio23 = new QRadioButton(this);jradio24 = new QRadioButton(this);jradio31 = new QRadioButton(this);jradio32 = new QRadioButton(this);jradio33 = new QRadioButton(this);jradio34 = new QRadioButton(this);jradio41 = new QRadioButton(this);jradio42 = new QRadioButton(this);jradio43 = new QRadioButton(this);jradio44 = new QRadioButton(this);jradio51 = new QRadioButton(this);jradio52 = new QRadioButton(this);jradio53 = new QRadioButton(this);jradio54 = new QRadioButton(this);jiaxiangG1 = new QWidget(this);jiaxiangG2 = new QWidget(this);jiaxiangG3 = new QWidget(this);jiaxiangG4 = new QWidget(this);jiaxiangG5 = new QWidget(this);jiaxiangH1 = new QHBoxLayout(this);jiaxiangH2 = new QHBoxLayout(this);jiaxiangH3 = new QHBoxLayout(this);jiaxiangH4 = new QHBoxLayout(this);jiaxiangH5 = new QHBoxLayout(this);jiaxiangH1->addWidget(jradio11);jiaxiangH1->addWidget(jradio12);jiaxiangH1->addWidget(jradio13);jiaxiangH1->addWidget(jradio14);jiaxiangG1->setLayout(jiaxiangH1);jiaxiangG1->setGeometry(QRect(705,205,250,35));jiaxiangH2->addWidget(jradio21);jiaxiangH2->addWidget(jradio22);jiaxiangH2->addWidget(jradio23);jiaxiangH2->addWidget(jradio24);jiaxiangG2->setLayout(jiaxiangH2);jiaxiangG2->setGeometry(QRect(705,280,250,35));jiaxiangH3->addWidget(jradio31);jiaxiangH3->addWidget(jradio32);jiaxiangH3->addWidget(jradio33);jiaxiangH3->addWidget(jradio34);jiaxiangG3->setLayout(jiaxiangH3);jiaxiangG3->setGeometry(QRect(705,365,250,35));jiaxiangH4->addWidget(jradio41);jiaxiangH4->addWidget(jradio42);jiaxiangH4->addWidget(jradio43);jiaxiangH4->addWidget(jradio44);jiaxiangG4->setLayout(jiaxiangH4);jiaxiangG4->setGeometry(QRect(705,445,250,35));jiaxiangH5->addWidget(jradio51);jiaxiangH5->addWidget(jradio52);jiaxiangH5->addWidget(jradio53);jiaxiangH5->addWidget(jradio54);jiaxiangG5->setLayout(jiaxiangH5);jiaxiangG5->setGeometry(QRect(705,525,250,35));

Simple implementation of qradiobutton grouping Without Borders

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.