114QSplashScreen::QSplashScreen(QScreen *screen,
const QPixmap &pixmap, Qt::WindowFlags f)
115 : QWidget(*(
new QSplashScreenPrivate()),
nullptr, Qt::SplashScreen | Qt::FramelessWindowHint | f)
118 d->setScreen(screen);
208 enum { TimeOutMs = 10 };
209 auto isMapped = [widget](){
210 return widget->windowHandle() && widget->windowHandle()->isVisible();
215 while (!isMapped()) {
216 const int remaining = timeout -
int(timer.elapsed());
219 QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
220 QCoreApplication::sendPostedEvents();
222 Sleep(uint(TimeOutMs));
224 struct timespec ts = { TimeOutMs / 1000, (TimeOutMs % 1000) * 1000 * 1000 };
225 nanosleep(&ts,
nullptr);
250void QSplashScreen::setPixmap(
const QPixmap &pixmap)
254 setAttribute(Qt::WA_TranslucentBackground, pixmap.hasAlpha());
256 const QRect r(QPoint(), pixmap.deviceIndependentSize().toSize());
259 move(screen()->geometry().center() - r.center());
286void QSplashScreen::drawContents(QPainter *painter)
289 painter->setPen(d->currColor);
290 QRect r = rect().adjusted(5, 5, -5, -5);
291 if (Qt::mightBeRichText(d->currStatus)) {
293#ifdef QT_NO_TEXTHTMLPARSER
294 doc.setPlainText(d->currStatus);
296 doc.setHtml(d->currStatus);
298 doc.setTextWidth(r.width());
299 QTextCursor cursor(&doc);
300 cursor.select(QTextCursor::Document);
301 QTextBlockFormat fmt;
302 fmt.setAlignment(Qt::Alignment(d->currAlign));
303 fmt.setLayoutDirection(layoutDirection());
304 cursor.mergeBlockFormat(fmt);
305 const QSizeF txtSize = doc.size();
306 if (d->currAlign & Qt::AlignBottom)
307 r.setTop(r.height() - txtSize.height());
308 else if (d->currAlign & Qt::AlignVCenter)
309 r.setTop(r.height() / 2 - txtSize.height() / 2);
311 painter->translate(r.topLeft());
312 doc.drawContents(painter);
315 painter->drawText(r, d->currAlign, d->currStatus);
319void QSplashScreenPrivate::handlePaintEvent()
323 painter.setRenderHints(QPainter::SmoothPixmapTransform);
324 painter.setLayoutDirection(q->layoutDirection());
325 if (!pixmap.isNull())
326 painter.drawPixmap(QPoint(), pixmap);
327 q->drawContents(&painter);