113QSplashScreen::QSplashScreen(QScreen *screen,
const QPixmap &pixmap, Qt::WindowFlags f)
114 : QWidget(*(
new QSplashScreenPrivate()),
nullptr, Qt::SplashScreen | Qt::FramelessWindowHint | f)
117 d->setScreen(screen);
207 enum { TimeOutMs = 10 };
208 auto isMapped = [widget](){
209 return widget->windowHandle() && widget->windowHandle()->isVisible();
214 while (!isMapped()) {
215 const int remaining = timeout -
int(timer.elapsed());
218 QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
219 QCoreApplication::sendPostedEvents();
221 Sleep(uint(TimeOutMs));
223 struct timespec ts = { TimeOutMs / 1000, (TimeOutMs % 1000) * 1000 * 1000 };
224 nanosleep(&ts,
nullptr);
249void QSplashScreen::setPixmap(
const QPixmap &pixmap)
253 setAttribute(Qt::WA_TranslucentBackground, pixmap.hasAlpha());
255 const QRect r(QPoint(), pixmap.deviceIndependentSize().toSize());
258 move(screen()->geometry().center() - r.center());
285void QSplashScreen::drawContents(QPainter *painter)
288 painter->setPen(d->currColor);
289 QRect r = rect().adjusted(5, 5, -5, -5);
290 if (Qt::mightBeRichText(d->currStatus)) {
292#ifdef QT_NO_TEXTHTMLPARSER
293 doc.setPlainText(d->currStatus);
295 doc.setHtml(d->currStatus);
297 doc.setTextWidth(r.width());
298 QTextCursor cursor(&doc);
299 cursor.select(QTextCursor::Document);
300 QTextBlockFormat fmt;
301 fmt.setAlignment(Qt::Alignment(d->currAlign));
302 fmt.setLayoutDirection(layoutDirection());
303 cursor.mergeBlockFormat(fmt);
304 const QSizeF txtSize = doc.size();
305 if (d->currAlign & Qt::AlignBottom)
306 r.setTop(r.height() - txtSize.height());
307 else if (d->currAlign & Qt::AlignVCenter)
308 r.setTop(r.height() / 2 - txtSize.height() / 2);
310 painter->translate(r.topLeft());
311 doc.drawContents(painter);
314 painter->drawText(r, d->currAlign, d->currStatus);
318void QSplashScreenPrivate::handlePaintEvent()
322 painter.setRenderHints(QPainter::SmoothPixmapTransform);
323 painter.setLayoutDirection(q->layoutDirection());
324 if (!pixmap.isNull())
325 painter.drawPixmap(QPoint(), pixmap);
326 q->drawContents(&painter);