(1)
++效果图:
(2)给出对应的搭建源代码,这是 QT 的编译器给出的正确的 C++ 代码:
#ifndef UI_WIDGET_H
#define UI_WIDGET_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QRadioButton>
#include <QtWidgets/QToolButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Widget
{
public:
QVBoxLayout *verticalLayout;
QGroupBox *groupBox;
QHBoxLayout *horizontalLayout;
QPushButton *pushButton;
QToolButton *toolButton;
QFrame *frame;
QHBoxLayout *horizontalLayout_2;
QCheckBox *checkBox;
QRadioButton *radioButton;
void setupUi(QWidget *Widget)
{
if (Widget->objectName().isEmpty())
Widget->setObjectName(QString::fromUtf8("Widget"));
Widget->resize(332, 284);
QFont font;
font.setPointSize(14);
Widget->setFont(font);
verticalLayout = new QVBoxLayout(Widget);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
groupBox = new QGroupBox(Widget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
horizontalLayout = new QHBoxLayout(groupBox);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
pushButton = new QPushButton(groupBox); //留意这三行代码是一组。这也是本文里提到的要学习的地方
pushButton->setObjectName(QString::fromUtf8("pushButton"));
horizontalLayout->addWidget(pushButton);
toolButton = new QToolButton(groupBox);
toolButton->setObjectName(QString::fromUtf8("toolButton"));
horizontalLayout->addWidget(toolButton);
verticalLayout->addWidget(groupBox);
frame = new QFrame(Widget);
frame->setObjectName(QString::fromUtf8("frame"));
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Raised);
horizontalLayout_2 = new QHBoxLayout(frame);
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
checkBox = new QCheckBox(frame);
checkBox->setObjectName(QString::fromUtf8("checkBox"));
horizontalLayout_2->addWidget(checkBox);
radioButton = new QRadioButton(frame);
radioButton->setObjectName(QString::fromUtf8("radioButton"));
horizontalLayout_2->addWidget(radioButton);
verticalLayout->addWidget(frame);
retranslateUi(Widget);
QMetaObject::connectSlotsByName(Widget);
} // setupUi
void retranslateUi(QWidget *Widget)
{
Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget2-1", nullptr));
groupBox->setTitle(QCoreApplication::translate("Widget", "GroupBox", nullptr));
pushButton->setText(QCoreApplication::translate("Widget", "PushButton", nullptr));
toolButton->setText(QCoreApplication::translate("Widget", "...", nullptr));
checkBox->setText(QCoreApplication::translate("Widget", "CheckBox", nullptr));
radioButton->setText(QCoreApplication::translate("Widget", "RadioButton", nullptr));
} // retranslateUi
};
namespace Ui {
class Widget: public Ui_Widget {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_WIDGET_H
(3)
谢谢