QT6 源(44):另一个容器 class QFrame : public QWidget , 记录 QFrame 的源码。只有布局才有添加子容器子布局的函数。即使是容器类也没有添加子控件的成员函数

(1)来自于头文件 qframe.h

#ifndef QFRAME_H
#define QFRAME_H

#include <QtWidgets/qtwidgetsglobal.h>
#include <QtWidgets/qwidget.h>

QT_BEGIN_NAMESPACE


class QFramePrivate;
class QStyleOptionFrame;


//    class QWidget : public QObject, public QPaintDevice
//    class QLayout : public QObject, public QLayoutIte
//可见,布局跟 Qwidget并不是继承关系。布局 QLayout与 窗体组件都继承于 QObject
//QWidget 是窗体上可见组件的基类,布局是不可见的。两者并没有继承关系。
//The QFrame class is the base class of widgets that can have a frame.
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.

    Q_PROPERTY(int frameWidth READ frameWidth)
    //This property holds the width of the frame that is drawn.
    //Note that the frame width depends on the frame style,
    //not only the line width and the mid-line width.
    //For example, the style specified by NoFrame always has a frame width of 0,
    //whereas the style Panel has a frame width equivalent to the line width.

    Q_PROPERTY(QRect frameRect READ frameRect WRITE setFrameRect DESIGNABLE false)
    //This property holds the frame's rectangle.
    //The frame's rectangle is the rectangle the frame is drawn in.
    //By default, this is the entire widget.
    //Setting the rectangle does does not cause a widget update.
    //The frame rectangle is automatically adjusted when the widget changes size.
    //If you set the rectangle to a null rectangle (for example, QRect(0, 0, 0, 0)),
    //then the resulting frame rectangle is equivalent to the widget rectangle.

private:
    Q_DISABLE_COPY(QFrame)  //禁止复制
    Q_DECLARE_PRIVATE(QFrame)
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)

    enum StyleMask {
        Shadow_Mask = 0x00f0, // mask for the shadow
        Shape_Mask  = 0x000f  // mask for the shape
    };

//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);

//Q_PROPERTY(int frameWidth READ frameWidth)
    int frameWidth() const;

//Q_PROPERTY(QRect frameRect READ frameRect WRITE setFrameRect DESIGNABLE false)
    QRect   frameRect() const;
    void setFrameRect(const QRect &);

    //Returns the frame style.  The default value is QFrame::Plain.
    int     frameStyle() const;
    void setFrameStyle(int);

    QSize sizeHint() const override;

protected:
    bool       event(QEvent *e) override;
    void  paintEvent(QPaintEvent *) override;
    void changeEvent(QEvent *) override;

    void   drawFrame(QPainter *); //无官方注释

protected:
    QFrame(QFramePrivate &dd, QWidget* parent = nullptr,
           Qt::WindowFlags f = Qt::WindowFlags());

    //Initializes option with the values from this QFrame.
    //This method is useful for subclasses when they need a QStyleOptionFrame but
    //don't want to fill in all the information themselves.
    virtual void initStyleOption(QStyleOptionFrame *option) const;

}; //完结 class QFrame : public QWidget

QT_END_NAMESPACE

#endif // QFRAME_H

(2)

在这里插入图片描述

(3)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值