QT6 源(76):滑动条类型中的 表盘QDial、滑动条QSliderBar、滚动条QScrollBar 的类对象生成的标准代码,来自于 ui_widget . h

(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)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangzhangkeji

谢谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值