QtCanpool 3.3.0
载入中...
搜索中...
未找到
QxApp::QxToast类 参考

One short message, shown over the window it belongs to and gone a few seconds later. 更多...

#include <qxapp/qxtoast.h>

类 QxApp::QxToast 继承关系图:

Public 类型

enum  Level { Information , Success , Warning , Error }
 What the message is about; it selects the icon and the accent colour. 更多...
 

Public 成员函数

 QxToast (const QString &text, Level level=Information, QWidget *parent=0)
 
 ~QxToast () override
 
QString text () const
 
void setText (const QString &text)
 Replaces the message; sizeHintChanged() follows when the size changed.
 
Level level () const
 
void setLevel (Level level)
 
int timeout () const
 Milliseconds left before the toast dismisses itself, zero or less when it is to stay until something dismisses it.
 
void setTimeout (int timeoutMs)
 
int fadeDuration () const
 
void setFadeDuration (int ms)
 Zero turns the animation off, which makes the life cycle immediate.
 
bool isPaused () const
 Whether the pointer is holding the countdown back right now.
 
bool isDismissing () const
 True from the moment dismiss() is called until the widget is gone.
 
QColor accentColor () const
 The colour the level is drawn with.
 
QSize sizeHint () const override
 
int heightForWidth (int width) const override
 Height of the whole widget when it is width wide, text wrapping included.
 
void start ()
 Puts the toast on screen, fades it in and starts the countdown.
 
void stop ()
 Stops the countdown and leaves the toast on screen.
 
void dismiss ()
 Takes the toast off screen: the countdown stops, the fade out runs and dismissed() follows once the widget is hidden.
 
void dismissRequested ()
 The toast wants to leave; emitted before the fade out starts.
 
void dismissed ()
 The toast is off screen.
 
void clicked ()
 The user clicked the toast.
 
void sizeHintChanged ()
 The preferred size changed and whoever placed the toast should look again.
 

静态 Public 属性

static constexpr int DefaultTimeout = 4000
 Milliseconds a toast stays on screen when the caller does not say.
 
static constexpr int DefaultFadeDuration = 160
 Milliseconds the fade in and the fade out take when no one says otherwise.
 
static constexpr int ShadowMargin = 4
 Pixels of room the widget keeps around its plate for the drop shadow.
 
static constexpr int MinPlateWidth = 160
 The narrowest and the widest plate a toast settles for, whatever width it is given.
 
static constexpr int MaxPlateWidth = 420
 

Protected 成员函数

void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
bool event (QEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 

详细描述

One short message, shown over the window it belongs to and gone a few seconds later.

A toast carries a Level - information, success, warning or error - which picks the icon and the accent colour, and it carries the text. Everything else about it is transient: it fades in, waits for its timeout, fades out and is destroyed. Hovering holds the countdown back, so a message that arrived while the pointer happened to be in the way does not vanish unread.

Applications normally talk to QxToastManager rather than to this class:

QxToastManager *toasts = new QxToastManager(mainWindow);
toasts->show(tr("The document was saved"), QxToast::Success);
toasts->show(tr("No printer is configured"), QxToast::Warning, 8000);
The stack of toasts of one window.
QxToast * show(const QString &text, QxToast::Level level=QxToast::Information, int timeoutMs=QxToast::DefaultTimeout)
Creates a toast, puts it at the end of the stack and starts it.

The class is a plain child widget of its host rather than a top level window of its own. That is deliberate: it needs no window manager to appear, the host's stacking order puts it above the ribbon and the docks for free, and it cannot take the keyboard focus away from the window the user is working in. A Qt::ToolTip window would need a platform window of its own and would behave differently under the offscreen platform and under WebAssembly, which is exactly where this class has to keep working.

The colours are read from the widget palette - the plate from QPalette::ToolTipBase, its border from QPalette::Mid, the accent from QPalette::Highlight - so a theme change reaches the toast without a line of code here.

在文件 qxtoast.h 第 53 行定义.

成员枚举类型说明

◆ Level

What the message is about; it selects the icon and the accent colour.

枚举值
Information 
Success 
Warning 
Error 

在文件 qxtoast.h 第 58 行定义.

构造及析构函数说明

◆ QxToast()

QxApp::QxToast::QxToast ( const QString &  text,
Level  level = Information,
QWidget *  parent = 0 
)
explicit

在文件 qxtoast.cpp 第 223 行定义.

◆ ~QxToast()

QxApp::QxToast::~QxToast ( )
override

在文件 qxtoast.cpp 第 234 行定义.

成员函数说明

◆ accentColor()

QColor QxApp::QxToast::accentColor ( ) const

The colour the level is drawn with.

Qt has no palette role for "success" or "warning", and writing four colours down here would freeze the toast against every theme. The theme's highlight colour therefore supplies saturation and lightness - so the accent stays as loud as the theme it runs under - and only the hue moves to the corner of the wheel the level is read in: the theme's own hue for information, green for success, amber for warning, red for error.

在文件 qxtoast.cpp 第 313 行定义.

◆ clicked()

void QxApp::QxToast::clicked ( )

The user clicked the toast.

◆ dismiss()

void QxApp::QxToast::dismiss ( )

Takes the toast off screen: the countdown stops, the fade out runs and dismissed() follows once the widget is hidden.

Calling it again on a toast that is already leaving changes nothing.

在文件 qxtoast.cpp 第 358 行定义.

◆ dismissed()

void QxApp::QxToast::dismissed ( )

The toast is off screen.

Its owner deletes the widget.

◆ dismissRequested()

void QxApp::QxToast::dismissRequested ( )

The toast wants to leave; emitted before the fade out starts.

◆ event()

bool QxApp::QxToast::event ( QEvent *  event)
overrideprotected

在文件 qxtoast.cpp 第 426 行定义.

◆ fadeDuration()

int QxApp::QxToast::fadeDuration ( ) const

在文件 qxtoast.cpp 第 289 行定义.

◆ heightForWidth()

int QxApp::QxToast::heightForWidth ( int  width) const
override

Height of the whole widget when it is width wide, text wrapping included.

在文件 qxtoast.cpp 第 325 行定义.

◆ isDismissing()

bool QxApp::QxToast::isDismissing ( ) const

True from the moment dismiss() is called until the widget is gone.

在文件 qxtoast.cpp 第 307 行定义.

◆ isPaused()

bool QxApp::QxToast::isPaused ( ) const

Whether the pointer is holding the countdown back right now.

在文件 qxtoast.cpp 第 301 行定义.

◆ level()

QxToast::Level QxApp::QxToast::level ( ) const

在文件 qxtoast.cpp 第 260 行定义.

◆ mouseReleaseEvent()

void QxApp::QxToast::mouseReleaseEvent ( QMouseEvent *  event)
overrideprotected

在文件 qxtoast.cpp 第 457 行定义.

◆ paintEvent()

void QxApp::QxToast::paintEvent ( QPaintEvent *  event)
overrideprotected

在文件 qxtoast.cpp 第 375 行定义.

◆ resizeEvent()

void QxApp::QxToast::resizeEvent ( QResizeEvent *  event)
overrideprotected

在文件 qxtoast.cpp 第 419 行定义.

◆ setFadeDuration()

void QxApp::QxToast::setFadeDuration ( int  ms)

Zero turns the animation off, which makes the life cycle immediate.

在文件 qxtoast.cpp 第 295 行定义.

◆ setLevel()

void QxApp::QxToast::setLevel ( Level  level)

在文件 qxtoast.cpp 第 266 行定义.

◆ setText()

void QxApp::QxToast::setText ( const QString &  text)

Replaces the message; sizeHintChanged() follows when the size changed.

在文件 qxtoast.cpp 第 245 行定义.

◆ setTimeout()

void QxApp::QxToast::setTimeout ( int  timeoutMs)

在文件 qxtoast.cpp 第 283 行定义.

◆ sizeHint()

QSize QxApp::QxToast::sizeHint ( ) const
override

在文件 qxtoast.cpp 第 319 行定义.

◆ sizeHintChanged()

void QxApp::QxToast::sizeHintChanged ( )

The preferred size changed and whoever placed the toast should look again.

◆ start()

void QxApp::QxToast::start ( )

Puts the toast on screen, fades it in and starts the countdown.

The manager calls this; calling it twice restarts the countdown.

在文件 qxtoast.cpp 第 331 行定义.

◆ stop()

void QxApp::QxToast::stop ( )

Stops the countdown and leaves the toast on screen.

在文件 qxtoast.cpp 第 351 行定义.

◆ text()

QString QxApp::QxToast::text ( ) const

在文件 qxtoast.cpp 第 239 行定义.

◆ timeout()

int QxApp::QxToast::timeout ( ) const

Milliseconds left before the toast dismisses itself, zero or less when it is to stay until something dismisses it.

在文件 qxtoast.cpp 第 277 行定义.

类成员变量说明

◆ DefaultFadeDuration

constexpr int QxApp::QxToast::DefaultFadeDuration = 160
staticconstexpr

Milliseconds the fade in and the fade out take when no one says otherwise.

在文件 qxtoast.h 第 69 行定义.

◆ DefaultTimeout

constexpr int QxApp::QxToast::DefaultTimeout = 4000
staticconstexpr

Milliseconds a toast stays on screen when the caller does not say.

在文件 qxtoast.h 第 67 行定义.

◆ MaxPlateWidth

constexpr int QxApp::QxToast::MaxPlateWidth = 420
staticconstexpr

在文件 qxtoast.h 第 82 行定义.

◆ MinPlateWidth

constexpr int QxApp::QxToast::MinPlateWidth = 160
staticconstexpr

The narrowest and the widest plate a toast settles for, whatever width it is given.

A host narrower than MinPlateWidth wins over the minimum, since a plate that does not fit is worse than a cramped one.

在文件 qxtoast.h 第 81 行定义.

◆ ShadowMargin

constexpr int QxApp::QxToast::ShadowMargin = 4
staticconstexpr

Pixels of room the widget keeps around its plate for the drop shadow.

A caller that positions a toast by hand has to allow for it; the manager does that itself.

在文件 qxtoast.h 第 75 行定义.


该类的文档由以下文件生成: