QT6 源(114):阅读与注释状态栏 QStatusBar,先进行属性与成员函数测试,接着是信号与槽函数测试,最后给出源码

(1) 先进行属性与成员函数测试

在这里插入图片描述

++
在这里插入图片描述

(2) 接着是信号与槽函数测试

在这里插入图片描述

++

在这里插入图片描述

(3)给出源码,来自于头文件 qstatusbar . h

#ifndef QSTATUSBAR_H
#define QSTATUSBAR_H

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

QT_REQUIRE_CONFIG(statusbar);

QT_BEGIN_NAMESPACE

class QStatusBarPrivate;

/*
The QStatusBar class provides a horizontal bar suitable for presenting status information.

每个状态指示符分为三类之一:
    临时-短暂占据状态栏的大部分。例如用于解释工具提示文本或菜单项。
    普通-占据状态栏的一部分,可能会被临时消息隐藏。例如用于在文字处理程序中显示页面和行号。
    永久的-永远不会隐藏。用于重要的模式指示,例如,一些应用程序在状态栏中放置大写锁定指示器。
QStatusBar 允许您显示所有三种类型的指示器。

通常,请求状态栏功能与 QMainWindow 对象相关。
QMainWindow提供主应用程序窗口,包括菜单栏、工具栏、停靠小部件和围绕大型中央小部件的状态栏。
可以使用QMainWindow::statusBar()函数检索状态栏,并使用 QMainWindow::setStatusBar()函数替换它。

Use the showMessage() slot to display a temporary message.

To remove a temporary message, use the clearMessage() slot,
or set a time limit when calling showMessage().
    //statusBar()->showMessage(tr("Ready"), 2000);

使用currentMessage()函数来检索当前显示的临时消息。
QStatusBar类还提供了messagechanged()信号,每当临时状态消息更改时都会发出该信号。

通过创建一个小部件(QLabel、QProgressBar甚至QToolButton),
并使用addWidget()或addPermanentWidget()函数将其添加到状态栏中,可以显示正常和永久消息。
使用removeWidget(函数将此类消息从状态栏中删除。

默认情况下,QStatusBar在右下角提供了一个QSizeGrip。
您可以使用 setSizeGripEnabled函数禁用它。
使用isSizeGripEnabled()函数来确定 size grip 的当前状态。

QStatusBar(状态栏)右下角的Size Grip(尺寸夹具)是一个用于调整窗口大小的交互控件。
经测试,没有之也一样可以鼠标拖动来调整窗体的大小。

*/

class Q_WIDGETS_EXPORT QStatusBar: public QWidget //说明本类继承于重要基类 QWidget。
{
    Q_OBJECT

    //This property holds whether the QSizeGrip in the bottom-right corner of the
    //status bar is enabled。The size grip is enabled by default.
    Q_PROPERTY(bool      sizeGripEnabled   //Size Grip(尺寸夹具)
                READ   isSizeGripEnabled   WRITE   setSizeGripEnabled)

private:
    Q_DISABLE_COPY(QStatusBar)
    Q_DECLARE_PRIVATE(QStatusBar)

public:
    //Constructs a status bar with a size grip and the given parent.
    explicit QStatusBar(QWidget * parent = nullptr);

    virtual ~QStatusBar();

//   Q_PROPERTY(bool      sizeGripEnabled   //Size Grip(尺寸夹具)
//              READ    isSizeGripEnabled   WRITE   setSizeGripEnabled)
                bool    isSizeGripEnabled() const;
                void   setSizeGripEnabled( bool );

    //Returns the temporary message currently shown,
    //  or an empty string if there is no such message.
    QString currentMessage() const;

    //将指定的小部件插入到此状态栏的给定索引处,
    //如果小部件不是此QStatusBar对象的子项,则重新将小部件作为子项。
    //如果索引超出范围,则将小部件附加(在这种情况下,返回的是小部件的实际索引)。
    //拉伸参数用于计算给定小部件的合适大小,因为状态栏会增长和缩小。
    //默认拉伸因子为0,即给小部件留出最少的空间。
    //The widget is located to the far left of the first permanent widget。
    //小部件位于第一个永久小部件的极左位置(见addPermanentWidget()),可能会被临时消息遮住。
    int    insertWidget(int index, QWidget * widget, int stretch = 0); //拉伸因子 0表示
    void      addWidget(           QWidget * widget, int stretch = 0); //给予最小的尺寸。
    // The default stretch factor is 0, i.e giving the widget a minimum of space。

    //Inserts the given widget at the given index permanently to this status bar。
    //永久的意思是,小部件可能不会受到临时消息的遮挡。它位于状态栏的最右侧。
    int    insertPermanentWidget(int index, QWidget * widget, int stretch = 0);
    void      addPermanentWidget(           QWidget * widget, int stretch = 0);

    void   removeWidget(QWidget * widget); //此删除非删除,而是隐藏。恢复时候要调用    show()
    //Removes the specified widget from the status bar.  //恢复时候要调用 QWidget::show()
    //Note: This function does not delete the widget but hides it.
    //To add the widget again, you must call both the addWidget() and show() functions.


public Q_SLOTS:
    //Hides the normal status indications and displays the given message for the
    //specified number of milli-seconds (timeout). If timeout is 0 (default),
    //the message remains displayed until the clearMessage() slot is called or until the
    //showMessage() slot is called again to change the message.
    //Note that showMessage() is called to show temporary explanations of tool tip texts,
    //so passing a timeout of 0 is not sufficient to display a permanent message.
    //经验证,即使 timeout给 0,状态栏也会迅速被按钮提示覆盖。这就是不等同于 permanent的表现、
    void showMessage(const QString & text, int timeout = 0); //形参2 的单位是毫秒 ms。
    void clearMessage(); //Removes any temporary message being shown.

Q_SIGNALS: //经验证,该信号函数的形参与 QStatusBar::currentMessage()的返回值等同。
    void messageChanged(const QString & message); //当状态栏为空时,形参传递进来空字符串。
    //This signal is emitted whenever the temporary status message changes.
    //The new temporary message is passed in the
    //  message parameter which is a null-string when the message has been removed.

protected:
    //更改状态栏的外观以反映项目更改。
    //特殊子类可能需要此函数,但几何图形管理通常会处理任何必要的重新排列。
    void reformat  ();
    void hideOrShow(); //Ensures that the right widgets are visible.
    //Used by the showMessage() and clearMessage() functions.

    bool       event(QEvent       *) override;
    void   showEvent(QShowEvent   *) override;
    void  paintEvent(QPaintEvent  *) override;
    void resizeEvent(QResizeEvent *) override;

}; //完结 class QStatusBar: public QWidget

QT_END_NAMESPACE

#endif // QSTATUSBAR_H

(4)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

zhangzhangkeji

谢谢支持

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

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

打赏作者

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

抵扣说明:

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

余额充值