QStatusBar 类

QStatusBar 类提供适于呈现状态信息的水平条。 更多...

Header: #include <QStatusBar>
CMake: find_package(Qt6 COMPONENTS Widgets REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QWidget

特性

公共函数

QStatusBar (QWidget * parent = 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)

信号

void messageChanged (const QString & message )

保护函数

void hideOrShow ()
void reformat ()

重实现保护函数

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

详细描述

Each status indicator falls into one of three categories:

  • Temporary - briefly occupies most of the status bar. Used to explain tool tip texts or menu entries, for example.
  • Normal - occupies part of the status bar and may be hidden by temporary messages. Used to display the page and line number in a word processor, for example.
  • Permanent - is never hidden. Used for important mode indications, for example, some applications put a Caps Lock indicator in the status bar.

QStatusBar lets you display all three types of indicators.

Typically, a request for the status bar functionality occurs in relation to a QMainWindow 对象。 QMainWindow provides a main application window, with a menu bar, tool bars, dock widgets and a status bar around a large central widget. The status bar can be retrieved using the QMainWindow::statusBar () function, and replaced using the QMainWindow::setStatusBar () 函数。

使用 showMessage () slot to display a temporary message:

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

To remove a temporary message, use the clearMessage () slot, or set a time limit when calling showMessage ()。例如:

void MainWindow::print()
{
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(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 () function to retrieve the temporary message currently shown. The QStatusBar class also provide the messageChanged () signal which is emitted whenever the temporary status message changes.

Normal and Permanent messages are displayed by creating a small widget ( QLabel , QProgressBar or even QToolButton ) and then adding it to the status bar using the addWidget () or the addPermanentWidget () function. Use the removeWidget () function to remove such messages from the status bar.

statusBar()->addWidget(new MyReadWriteIndication);
							

By default QStatusBar provides a QSizeGrip in the lower-right corner. You can disable it using the setSizeGripEnabled () function. Use the isSizeGripEnabled () function to determine the current status of the size grip.

A status bar shown in the Fusion widget style

另请参阅 QMainWindow , QStatusTipEvent , GUI Design Handbook: Status Bar ,和 Qt Widgets - 应用程序范例 .

特性文档编制

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 = nullptr)

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

另请参阅 setSizeGripEnabled ().

[slot] void QStatusBar:: clearMessage ()

Removes any temporary message being shown.

另请参阅 currentMessage (), showMessage (),和 removeWidget ().

[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 () 和 clearMessage ().

[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 )。若 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 (),和 clearMessage ().

[virtual] QStatusBar:: ~QStatusBar ()

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

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

添加给定 widget permanently to this status bar, reparenting the widget if it isn't already a child of this QStatusBar 对象。 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 (),和 addWidget ().

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

添加给定 widget to this status bar, reparenting the widget if it isn't already a child of this QStatusBar 对象。 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 (),和 addPermanentWidget ().

QString QStatusBar:: currentMessage () const

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

另请参阅 showMessage ().

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

重实现: QWidget::event (QEvent *event).

[protected] void QStatusBar:: hideOrShow ()

Ensures that the right widgets are visible.

Used by the showMessage () 和 clearMessage () 函数。

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

Inserts the given widget 在给定 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).

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.

另请参阅 addPermanentWidget (), removeWidget (),和 addWidget ().

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

Inserts the given widget 在给定 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).

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.

另请参阅 addWidget (), removeWidget (),和 addPermanentWidget ().

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

重实现: QWidget::paintEvent (QPaintEvent *event).

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 )

移除指定 widget from the status bar.

注意: This function does not delete the widget but hides it. To add the widget again, you must call both the addWidget () 和 show () 函数。

另请参阅 addWidget (), addPermanentWidget (),和 clearMessage ().

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

重实现: QWidget::resizeEvent (QResizeEvent *event).

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

重实现: QWidget::showEvent (QShowEvent *event).