QSplashScreen Class
The QSplashScreen class shows a picture while the application starts. More…
| Header | #include <QSplashScreen> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
List of all members, including inherited members
Public Functions
| QSplashScreen(const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags()) | |
| ~QSplashScreen() | |
| void | setPixmap(const QPixmap &pixmap) |
| QPixmap | pixmap() const |
| void | finish(QWidget *mainWin) |
| QString | message() const |
Reimplemented Public Functions
Public Slots
| void | showMessage(const QString &message, int alignment = Qt::AlignLeft, const QColor &color = Qt::black) |
| void | clearMessage() |
Signals
| void | messageChanged(const QString &message) |
Protected Functions
| virtual void | drawContents(QPainter *painter) |
Reimplemented Protected Functions
| bool | eventFilter(QObject *watched, QEvent *event) |
| void | paintEvent(QPaintEvent *event) |
| void | mousePressEvent(QMouseEvent *event) |
Detailed Description
A splash screen is a frameless window in the middle of the screen with a pixmap and a message. Show it before the main window is made, and let it close when the main window shows:
QPixmap picture(400, 200);
picture.fill(Qt::darkCyan);
QSplashScreen splash(picture);
splash.show();
splash.showMessage("Loading plugins...", Qt::AlignBottom | Qt::AlignHCenter, Qt::white);
loadPlugins();
MainWindow window;
window.show();
splash.finish(&window);
The message is drawn over the pixmap; reimplement drawContents() to draw more. showMessage() repaints at once, so the message is seen even while the application is busy. A click closes the splash screen.
See also QPixmap.
Differences from Qt
There is no QSplashScreen(QScreen *) constructor, and pixmaps cannot be loaded from files in Nt, so the pixmap is painted by the application.
Member Function Documentation
QSplashScreen::QSplashScreen(const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags())
Constructs a splash screen with the given pixmap and window flags f. It is a frameless window that stays on top.
QSplashScreen::~QSplashScreen()
Destroys the splash screen.
void QSplashScreen::clearMessage()
Removes the message.
void QSplashScreen::drawContents(QPainter *painter)
Draws the message with painter. Reimplement it to draw more over the pixmap.
bool QSplashScreen::eventFilter(QObject *watched, QEvent *event)
Reimplements QWidget::eventFilter().
The splash screen closes when the window given to finish() is shown.
void QSplashScreen::finish(QWidget *mainWin)
Closes the splash screen when mainWin is shown, or at once if it is shown already.
QString QSplashScreen::message() const
Returns the message that is shown, or an empty string.
void QSplashScreen::messageChanged(const QString &message)
This signal is emitted when the message changes to message.
void QSplashScreen::mousePressEvent(QMouseEvent *event)
Reimplements QWidget::mousePressEvent().
A click hides the splash screen.
void QSplashScreen::paintEvent(QPaintEvent *event)
Reimplements QWidget::paintEvent().
QPixmap QSplashScreen::pixmap() const
Returns the pixmap of the splash screen.
void QSplashScreen::setPixmap(const QPixmap &pixmap)
Sets the pixmap of the splash screen to pixmap; the window takes its size and moves to the middle of the screen.
See also pixmap().
void QSplashScreen::showMessage(const QString &message, int alignment = Qt::AlignLeft, const QColor &color = Qt::black)
Shows message over the pixmap, placed by alignment, in color, and repaints at once.
See also clearMessage() and messageChanged().
QSize QSplashScreen::sizeHint() const
Reimplements QWidget::sizeHint().