QT6 源(73):UI界面里控件盒子里 Display Widgets 输出展示部分的水平直线、垂直直线控件,居然是是 QFrame 这个容器的实例化对象,给出源码举例

(1)因为老师讲的例题里用到了这个直线,再学习下

在这里插入图片描述

++

在这里插入图片描述

(2)由 QT 的 UIC 界面编译器生成的 c++ 代码,头文件 ui_widget.h 重的完整内容如下,其会讲解直线的生成

#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/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Widget
{
public:
    QVBoxLayout * verticalLayout_3;  //窗体的布局样式
    QGroupBox   * groupBox_2;
    QVBoxLayout *verticalLayout;
    QCheckBox   * checkBox_2;
    QFrame      * line_2;           //那条垂直线
    QPushButton * pushButton_3;
    QFrame      * line;             //那条水平线,居然是框架 QFrame

    void setupUi(QWidget *Widget)
    {
        if (Widget->objectName().isEmpty())
            Widget->setObjectName(QString::fromUtf8("Widget"));
            
        Widget->resize(189, 154);
        QFont font;
        font.setPointSize(14);
        Widget->setFont(font);
        
        verticalLayout_3 = new QVBoxLayout(Widget); //窗体的总布局
        verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
        
        groupBox_2 = new QGroupBox(Widget);         //生成容器并采用垂直布局
        groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
        verticalLayout = new QVBoxLayout(groupBox_2);
        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));

        checkBox_2 = new QCheckBox(groupBox_2);    //添加第一个占位的复选框
        checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
        verticalLayout->addWidget(checkBox_2);

        line_2 = new QFrame(groupBox_2);
        line_2->setObjectName(QString::fromUtf8("line_2"));
        line_2->setFrameShadow(QFrame::Plain);     //普通,这是框架的阴影的样式啊, shadow
        line_2->setLineWidth(3);
        line_2->setMidLineWidth(0);
        line_2->setFrameShape(QFrame::VLine);      //此渲染为垂直线
        verticalLayout->addWidget(line_2);         //把垂直线加入容器

        pushButton_3 = new QPushButton(groupBox_2);
        pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
        pushButton_3->setCheckable(false);
        pushButton_3->setChecked(false);
        pushButton_3->setAutoExclusive(false);
        pushButton_3->setAutoDefault(false);
        pushButton_3->setFlat(false);
        verticalLayout->addWidget(pushButton_3);

        line = new QFrame(groupBox_2);
        line->setObjectName(QString::fromUtf8("line"));
        line->setFrameShadow(QFrame::Raised);    //阴影的效果是物体凸起的感觉
        line->setLineWidth(3);                   //线宽也是 3 
        line->setFrameShape(QFrame::HLine);      //显示为水平线
        verticalLayout->addWidget(line);

        verticalLayout_3->addWidget(groupBox_2); //容器也被加入了窗体

        retranslateUi(Widget);

        pushButton_3->setDefault(false);

        QMetaObject::connectSlotsByName(Widget);
    } // setupUi

    void retranslateUi(QWidget *Widget)
    {
        Widget      ->setWindowTitle(QCoreApplication::translate("Widget", "Widget2-1", nullptr));
        groupBox_2  ->setTitle(QCoreApplication::translate("Widget", "GroupBox2"  , nullptr));
        checkBox_2  ->setText(QCoreApplication ::translate("Widget", "CheckBox"   , nullptr));
        pushButton_3->setText(QCoreApplication ::translate("Widget", "PushButton3", nullptr));
    } // retranslateUi

};

namespace Ui {
    class Widget: public Ui_Widget {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_WIDGET_H

(3) 上面例子里涉及的 QFrame 的源码支持,不全,精简版

class Q_WIDGETS_EXPORT QFrame : public QWidget
{
    Q_OBJECT //又插入了此宏

    //取值如:Box  Panel  WinPanel  HLine  VLine。宏定义取值在本文件
    //This property holds the frame shape value from the frame style
    Q_PROPERTY(Shape  frameShape  READ frameShape  WRITE setFrameShape )

    Q_PROPERTY(Shadow frameShadow READ frameShadow WRITE setFrameShadow)
    //This property holds the frame shadow value from the frame style
    //取值为:Plain    Raised   Sunken沉没。   宏定义取值在本文件

    //此属性保存行宽。 默认值为 1。
    //请注意,用作分隔符的框架(HLine和VLine)的总行宽是由frameWidth指定的。
    Q_PROPERTY(int lineWidth    READ lineWidth     WRITE setLineWidth)

    Q_PROPERTY(int midLineWidth READ midLineWidth WRITE setMidLineWidth)
    //This property holds the width of the mid-line
    //The default value is 0.
    
public:
    //WindowFlags = QFlags<WindowType> 描述本窗体是普通窗体还是对话框、弹出框等
    explicit QFrame(QWidget * parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
    //Constructs a frame widget with frame style NoFrame and a 1-pixel frame width.
    //The parent and f arguments are passed to the QWidget constructor.

    ~QFrame();

    enum Shape {
        NoFrame     =      0, // no frame
        Box         = 0x0001, // rectangular box
        Panel       = 0x0002, // rectangular panel
        WinPanel    = 0x0003, // rectangular panel (Windows)
        HLine       = 0x0004, // horizontal  line
        VLine       = 0x0005, // vertical    line
        StyledPanel = 0x0006  // rectangular panel depending on the GUI style
    };
    Q_ENUM(Shape)  //把本枚举类注册到元对象系统

    enum Shadow {
        Plain  = 0x0010, // plain line
        Raised = 0x0020, // raised shadow effect
        Sunken = 0x0030  // sunken shadow effect
    };
    Q_ENUM(Shadow)

//Q_PROPERTY(Shape  frameShape  READ frameShape  WRITE setFrameShape )
    Shape   frameShape() const;
    void setFrameShape(Shape);

//Q_PROPERTY(Shadow frameShadow READ frameShadow WRITE setFrameShadow)
    Shadow     frameShadow() const;
    void    setFrameShadow(Shadow);

//Q_PROPERTY(int lineWidth    READ lineWidth     WRITE setLineWidth)
    int     lineWidth() const;
    void setLineWidth(int);

//Q_PROPERTY(int midLineWidth READ midLineWidth WRITE setMidLineWidth)
    int     midLineWidth() const;
    void setMidLineWidth(int);

//......................................略

}; //完结 class QFrame : public QWidget

(4)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

zhangzhangkeji

谢谢支持

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

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

打赏作者

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

抵扣说明:

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

余额充值