I have a splash screen image that I display with splash.showFullScreen() but it doesn't re size it to the screen resolution so it either comes out tiled or to large depending on the display. I have tried everything I can think of but nothing works. This might sound like a stupid question which it probably is but I can't find the answer so if any can just help me with this? If it makes a difference I use a QPixmap named pixmap for the splash image. By the way I want the image to be stretched to the screen resolution.
You should scale the pixmap to the size of the screen with QPixmap::scaled(). You can get the screen resolution by calling QDesktopWidget::screenGeometry(). The desktop widget can be obtained by QApplication::desktop().
You can try something like this:
QDesktopWidget* desktopWidget = qApp->desktop();
QRect screenGeometry = desktopWidget->screenGeometry();
int screenWidth = screenGeometry.width();
int screenHeight = screenGeometry.height();
QPixmap pixmapForSplash = yourPixmap.scaled(screenWidth, screenHeight);
QSplashScreen splashScreen(pixmapForSplash);
(I'm sorry, I can not check this, because I do not have a development environment on this computer... I hope it is correct.)
QSplashScreen
using showFullScreen()
already sets the size of the QSplashScreen
widget to size of the screen. –
Guss I think you should call resize()
method for your splash screen by the size of the available desktop geometry that you can get using QDesktopWidget::availableGeometry
method. The QApplication::desktop()
function is used to get an instance of QDesktopWidget
.
slpashScreen.resize(QApplication::desktop()->avaiableGeometry().size());
QSplashScreen
using showFullScreen()
already sets the size of the QSplashScreen
widget to size of the screen. –
Guss resize
doesn't fulfill the purpose, in that case QDesktopWidget::availableGeometry
works.. –
Cocktail If you use a QLabel to display the image, make sure the label is in a layout that will cause it to fill the entire parent widget and set the label to scale its contents using setScaledContents(true).
QSplashScreen
but it just looks like it has some convenience features for typical splash screen behaviour. It is still a QWidget
though so I'd say just add a layout, and add a QLabel
to it. Then set the pixmap in the label and set the label to scale its contents. –
Guss © 2022 - 2024 — McMap. All rights reserved.