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.

Gerharddc
  • 3,921
  • 8
  • 45
  • 83
  • 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? – karlphillip Nov 19 '11 at 07:07
  • I don't care if it's stretched as long as it's not tiled or outside the screen – Gerharddc Nov 19 '11 at 07:08

3 Answers3

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

Bill
  • 11,595
  • 6
  • 44
  • 52
  • This sounds good could you just explain in more detail how to use it for someone stupid as me? – Gerharddc Nov 19 '11 at 08:13
  • 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. – Arnold Spence Nov 19 '11 at 08:31
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());

  • 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. – Arnold Spence Nov 19 '11 at 08:32
  • It should be pixmap.scaled(QApplication::desktop()->avaiableGeometry().size()) to work – Gerharddc Nov 19 '11 at 08:41
  • 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.. – Tejendra Apr 16 '16 at 14:29
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).

Arnold Spence
  • 21,942
  • 7
  • 74
  • 67
  • I use QSplashScreen if you could please help me with that? – Gerharddc Nov 19 '11 at 08:09
  • 2
    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. – Arnold Spence Nov 19 '11 at 08:14