简体   繁体   English

Qt屏幕分辨率飞溅屏幕

[英]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. 我有一个启动画面图像,我用splash.showFullScreen()显示,但它不会调整大小到屏幕分辨率,所以它要么是平铺,要么是根据显示器大。 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. 如果它有所不同,我使用名为pixmap的QPixmap作为启动图像。 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() . 您应该使用QPixmap :: scaled()将像素图缩放到屏幕大小。 You can get the screen resolution by calling QDesktopWidget::screenGeometry() . 您可以通过调用QDesktopWidget :: screenGeometry()来获得屏幕分辨率。 The desktop widget can be obtained by QApplication::desktop() . 可以通过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.) (对不起,我无法检查这个,因为我在这台电脑上没有开发环境......我希望它是正确的。)

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. 我认为你应该根据可以使用QDesktopWidget::availableGeometry方法获得的可用桌面几何体的大小为你的启动画面调用resize()方法。 The QApplication::desktop() function is used to get an instance of QDesktopWidget . QApplication::desktop()函数用于获取QDesktopWidget的实例。 slpashScreen.resize(QApplication::desktop()->avaiableGeometry().size());

如果使用QLabel显示图像,请确保标签位于布局中,使其填充整个父窗口小部件并设置标签以使用setScaledContents(true)缩放其内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM