(1)搭建的界面如下 :
(2)
(3)对应的 UIC 生成的头文件
:
#ifndef UI_WIDGET_H
#define UI_WIDGET_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDial>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QSlider>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Widget
{
public:
QVBoxLayout * verticalLayout_2 ; //窗体的布局
QGroupBox * groupBox ;
QHBoxLayout * horizontalLayout_2 ; //上容器的布局
QDial * dial ;
QFrame * frame ;
QHBoxLayout * horizontalLayout ;
QScrollBar * verticalScrollBar ;
QSlider * verticalSlider ;
QGroupBox * groupBox_2 ;
QVBoxLayout * verticalLayout ; //下容器的布局样式
QSlider * horizontalSlider ;
QScrollBar * horizontalScrollBar;
void setupUi(QWidget *Widget)
{
if (Widget->objectName().isEmpty())
Widget->setObjectName(QString::fromUtf8("Widget"));
Widget->resize(345, 272);
QFont font;
font.setPointSize(14);
Widget->setFont(font);
verticalLayout_2 = new QVBoxLayout(Widget); //为窗体设置布局
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
groupBox = new QGroupBox(Widget); //生成上面的容器
groupBox->setObjectName(QString::fromUtf8("groupBox"));
horizontalLayout_2 = new QHBoxLayout(groupBox);
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
dial = new QDial(groupBox); //表盘的生成代码
dial->setObjectName(QString::fromUtf8("dial"));
dial->setValue(73);
dial->setSliderPosition(73);
dial->setInvertedControls(false);
dial->setNotchTarget(13.000000000000000);
dial->setNotchesVisible(true);
horizontalLayout_2->addWidget(dial);
frame = new QFrame(groupBox); //上容器中的子容器 QFrame
frame->setObjectName(QString::fromUtf8("frame"));
frame->setFrameShape(QFrame::Panel);
frame->setFrameShadow(QFrame::Raised);
frame->setLineWidth(7);
frame->setMidLineWidth(2);
horizontalLayout = new QHBoxLayout(frame);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
verticalScrollBar = new QScrollBar(frame); //垂直滚条的生成
verticalScrollBar->setObjectName(QString::fromUtf8("verticalScrollBar"));
verticalScrollBar->setValue(1);
verticalScrollBar->setSliderPosition(1);
verticalScrollBar->setOrientation(Qt::Vertical); //该属性的设置造成垂直的视觉效果
verticalScrollBar->setInvertedAppearance(false);
verticalScrollBar->setInvertedControls(false);
horizontalLayout->addWidget(verticalScrollBar);
verticalSlider = new QSlider(frame); //垂直滑动条的生成代码
verticalSlider->setObjectName(QString::fromUtf8("verticalSlider"));
verticalSlider->setSliderPosition(1);
verticalSlider->setOrientation(Qt::Vertical); //该属性的设置造成垂直的视觉效果
horizontalLayout->addWidget(verticalSlider);
horizontalLayout_2->addWidget(frame); //上面的容器吸收 QFrame子容器
//void QBoxLayout::setStretch(int index, int stretch); //给 index控件设置伸缩因子
horizontalLayout_2->setStretch(1, 2); //上面的容器设置列宽的比例
verticalLayout_2->addWidget(groupBox); //把上面的容器加入窗体
groupBox_2 = new QGroupBox(Widget); //生成下面的容器
groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
verticalLayout = new QVBoxLayout(groupBox_2);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
horizontalSlider = new QSlider(groupBox_2); //水平滑动条的生成
horizontalSlider->setObjectName(QString::fromUtf8("horizontalSlider"));
horizontalSlider->setSliderPosition(16);
horizontalSlider->setTracking(false);
horizontalSlider->setOrientation(Qt::Horizontal);
horizontalSlider->setInvertedAppearance(false);
horizontalSlider->setInvertedControls(false);
verticalLayout->addWidget(horizontalSlider); //把水平滑动条添加入下容器
horizontalScrollBar = new QScrollBar(groupBox_2); //水平滚动条的生成
horizontalScrollBar->setObjectName(QString::fromUtf8("horizontalScrollBar"));
horizontalScrollBar->setSliderPosition(16);
horizontalScrollBar->setOrientation(Qt::Horizontal);
verticalLayout->addWidget(horizontalScrollBar); //把水平滚动条添加入下容器
verticalLayout_2->addWidget(groupBox_2); //把下容器加入窗体
//void QBoxLayout::setStretch(int index, int stretch); //给 index控件设置伸缩因子
verticalLayout_2->setStretch(0, 3); //设置窗体的行高的比例, 0 行的行高是 3
verticalLayout_2->setStretch(1, 2); // 1 行的行高是 2
retranslateUi(Widget);
QMetaObject::connectSlotsByName(Widget);
} // setupUi
void retranslateUi(QWidget *Widget)
{
Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget2-1", nullptr));
groupBox ->setTitle (QCoreApplication::translate("Widget", "GroupBox1", nullptr));
groupBox_2->setTitle (QCoreApplication::translate("Widget", "GroupBox2", nullptr));
} // retranslateUi
};
namespace Ui {
class Widget: public Ui_Widget {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_WIDGET_H
(4)
谢谢