Qt Screen Resolution Splash Screen
Asked Answered
E

3

5

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.

Ehrenburg answered 19/11, 2011 at 7:0 Comment(2)
Can you provide samples images? The original image and the one that is being displayed? Do you want to keep the aspect ratio of the image? Or do you want it to be stretched to the size of the window?Indicant
I don't care if it's stretched as long as it's not tiled or outside the screenEhrenburg
K
8

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.)

Known answered 19/11, 2011 at 8:12 Comment(2)
This sounds good could you just explain in more detail how to use it for someone stupid as me?Ehrenburg
It shouldn't be necessary to query for desktop screen geometry. Displaying the QSplashScreen using showFullScreen() already sets the size of the QSplashScreen widget to size of the screen.Guss
R
2

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());

Rowel answered 19/11, 2011 at 8:22 Comment(3)
It shouldn't be necessary to query for desktop screen geometry. Displaying the QSplashScreen using showFullScreen() already sets the size of the QSplashScreen widget to size of the screen.Guss
It should be pixmap.scaled(QApplication::desktop()->avaiableGeometry().size()) to workEhrenburg
Well resize doesn't always works, actually it depends upon your display manager, if you have a limited linux desktop environment then resize doesn't fulfill the purpose, in that case QDesktopWidget::availableGeometry works..Cocktail
G
1

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).

Guss answered 19/11, 2011 at 8:6 Comment(2)
I use QSplashScreen if you could please help me with that?Ehrenburg
I've never used 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.