Search code examples
c++qtsplash-screenscreen-resolutionqpixmap

Qt Screen Resolution Splash Screen


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.


Solution

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