QStatusBar Class

QStatusBar 提供一个显示状态信息的水平条. 更多...

头文件: #include <QStatusBar>
qmake: QT += widgets
基类: QWidget

属性

公有函数

QStatusBar(QWidget *parent = Q_NULLPTR)
virtual ~QStatusBar()
void addPermanentWidget(QWidget *widget, int stretch = 0)
void addWidget(QWidget *widget, int stretch = 0)
QString currentMessage() const
int insertPermanentWidget(int index, QWidget *widget, int stretch = 0)
int insertWidget(int index, QWidget *widget, int stretch = 0)
bool isSizeGripEnabled() const
void removeWidget(QWidget *widget)
void setSizeGripEnabled(bool)

公有槽函数

void clearMessage()
void showMessage(const QString &message, int timeout = 0)
  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject

信号

void messageChanged(const QString &message)

受保护的函数

void hideOrShow()
void reformat()

重新实现的受保护函数

virtual bool event(QEvent *e)
virtual void paintEvent(QPaintEvent *event)
virtual void resizeEvent(QResizeEvent *e)
virtual void showEvent(QShowEvent *)
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

QStatusBar 提供一个显示状态信息的水平条.

每个状态指示分为三类:

  • 临时 - 短期占据状态栏的大部分区域. 如, 工具或菜单的释义文本.
  • 正常 - 占据部分状态栏, 可能被临时信息隐藏. 如, 文字处理程序中显示的页码和行号.
  • 永久 - 永远不会隐藏. 重要信息显示. 如, 某些应用程序放置大写锁定信息.

QStatusBar 允许显示三种类型状态.

通常, 状态栏的功能与 QMainWindow 对象相关. QMainWindow 提供一个应用程序的主窗口, 包含一个菜单栏, 工具栏, 停靠窗口 一个状态栏. 调用 QMainWindow::statusBar() 函数获取状态栏指针, 调用 QMainWindow::setStatusBar() 替换状态栏.

调用公有槽函数 showMessage() 显示 临时 信息:


  void MainWindow::createStatusBar()
  {
      statusBar()->showMessage(tr("Ready"));
  }

删除临时消息,使用公有槽函数 clearMessage(), 或调用 showMessage()时通过参数设置时间限制. 例如:


  void MainWindow::print()
  {
  #ifndef QT_NO_PRINTDIALOG
      QTextDocument *document = textEdit->document();
      QPrinter printer;

      QPrintDialog dlg(&printer, this);
      if (dlg.exec() != QDialog::Accepted) {
          return;
      }

      document->print(&printer);
      statusBar()->showMessage(tr("Ready"), 2000);
  #endif
  }

使用 currentMessage() 函数获取当前显示的临时消息. QStatusBar 还提供 messageChanged() 信号, 这个信号在临时状态消息更改时发出.

Qt显示正常永久 消息还有另一种方式, 先创建一个widget (QLabel, QProgressBarQToolButton) 然后调用 addWidget() 或 addPermanentWidget() 函数将其添加到状态栏. 使用 removeWidget() 函数从状态栏删除消息.


  statusBar()->addWidget(new MyReadWriteIndication);

默认情况下, QStatusBar 在右下角提供 QSizeGrip. 你也可以调用 setSizeGripEnabled() 函数禁用它. 调用 isSizeGripEnabled()函数判断QSizeGrip的当前状态.

A status bar shown in the Fusion widget style

参见 QMainWindow, QStatusTipEvent, GUI Design Handbook: Status Bar, Application Example.

属性

sizeGripEnabled : bool

This property holds whether the QSizeGrip in the bottom-right corner of the status bar is enabled

The size grip is enabled by default.

访问函数:

bool isSizeGripEnabled() const
void setSizeGripEnabled(bool)

成员函数

QStatusBar::QStatusBar(QWidget *parent = Q_NULLPTR)

Constructs a status bar with a size grip and the given parent.

参见 setSizeGripEnabled().

[virtual] QStatusBar::~QStatusBar()

Destroys this status bar and frees any allocated resources and child widgets.

void QStatusBar::addPermanentWidget(QWidget *widget, int stretch = 0)

Adds the given widget permanently to this status bar, reparenting the widget if it isn't already a child of this QStatusBar object. The stretch parameter is used to compute a suitable size for the given widget as the status bar grows and shrinks. The default stretch factor is 0, i.e giving the widget a minimum of space.

Permanently means that the widget may not be obscured by temporary messages. It is is located at the far right of the status bar.

参见 insertPermanentWidget(), removeWidget(), and addWidget().

void QStatusBar::addWidget(QWidget *widget, int stretch = 0)

Adds the given widget to this status bar, reparenting the widget if it isn't already a child of this QStatusBar object. The stretch parameter is used to compute a suitable size for the given widget as the status bar grows and shrinks. The default stretch factor is 0, i.e giving the widget a minimum of space.

The widget is located to the far left of the first permanent widget (see addPermanentWidget()) and may be obscured by temporary messages.

参见 insertWidget(), removeWidget(), and addPermanentWidget().

[slot] void QStatusBar::clearMessage()

Removes any temporary message being shown.

参见 currentMessage(), showMessage(), and removeWidget().

QString QStatusBar::currentMessage() const

Returns the temporary message currently shown, or an empty string if there is no such message.

参见 showMessage().

[virtual protected] bool QStatusBar::event(QEvent *e)

重新实现 QObject::event().

[protected] void QStatusBar::hideOrShow()

Ensures that the right widgets are visible.

Used by the showMessage() and clearMessage() functions.

int QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch = 0)

Inserts the given widget at the given index permanently to this status bar, reparenting the widget if it isn't already a child of this QStatusBar object. If index is out of range, the widget is appended (in which case it is the actual index of the widget that is returned).

The stretch parameter is used to compute a suitable size for the given widget as the status bar grows and shrinks. The default stretch factor is 0, i.e giving the widget a minimum of space.

Permanently means that the widget may not be obscured by temporary messages. It is is located at the far right of the status bar.

This function was introduced in Qt 4.2.

参见 addPermanentWidget(), removeWidget(), and addWidget().

int QStatusBar::insertWidget(int index, QWidget *widget, int stretch = 0)

Inserts the given widget at the given index to this status bar, reparenting the widget if it isn't already a child of this QStatusBar object. If index is out of range, the widget is appended (in which case it is the actual index of the widget that is returned).

The stretch parameter is used to compute a suitable size for the given widget as the status bar grows and shrinks. The default stretch factor is 0, i.e giving the widget a minimum of space.

The widget is located to the far left of the first permanent widget (see addPermanentWidget()) and may be obscured by temporary messages.

This function was introduced in Qt 4.2.

参见 addWidget(), removeWidget(), and addPermanentWidget().

[signal] void QStatusBar::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.

参见 showMessage() and clearMessage().

[virtual protected] void QStatusBar::paintEvent(QPaintEvent *event)

重新实现 QWidget::paintEvent().

Shows the temporary message, if appropriate, in response to the paint event.

[protected] void QStatusBar::reformat()

Changes the status bar's appearance to account for item changes.

Special subclasses may need this function, but geometry management will usually take care of any necessary rearrangements.

void QStatusBar::removeWidget(QWidget *widget)

Removes the specified widget from the status bar.

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.

参见 addWidget(), addPermanentWidget(), and clearMessage().

[virtual protected] void QStatusBar::resizeEvent(QResizeEvent *e)

重新实现 QWidget::resizeEvent().

[virtual protected] void QStatusBar::showEvent(QShowEvent *)

重新实现 QWidget::showEvent().

[slot] void QStatusBar::showMessage(const QString &message, int timeout = 0)

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.

参见 messageChanged(), currentMessage(), and clearMessage().