有人可以告诉我,是否可以在没有任何布局的情况下使用QWidget
。我有QSplashScreen
以图片作为背景,我想在我的启动画面中再添加一个QLabel
和另一张图片,但由于启动画面无法调整大小且没有理由这样做,我我们不想使用任何Layout
。我只想添加QLabel
图像并设置其几何图形。
答案 0 :(得分:5)
没有任何内容:只需将您的小部件添加为初始屏幕的子项,并手动设置其位置,也可以设置大小。
int main(int argc, char ** argv) {
QApplication a{argc, argv};
QSplashScreen splash;
QLabel image{&splash};
image.move(50, 50);
...
splash.show();
return a.exec();
}
答案 1 :(得分:2)
与Kuba Ober的上述代码大致相同,但有一些细微但必要的补充。
QPixmap pixmap(":/splash.png"); //from resources
QSplashScreen splash(pixmap);
QLabel label(&splash);
label.setPixmap(pixmap); //you can use different image for label
label.setScaledContents(true);
label.setGeometry(50,50,50,50);
splash.show();