NRUB
NRUB

Reputation: 374

Qt how to put QLabel without any layout

Can someone tell me, is it possible to use QWidget without any Layout. I have QSplashScreen with image as a background and I want to add one more QLabel with another image inside of my splash screen, but because splash screen is not resizable and there is no reason to do this, I haven't want use any Layout. I want just add QLabel with image and set its geometry.

Upvotes: 1

Views: 1691

Answers (2)

There's nothing to it: just add your widget as a child of the splash screen, and manually set its position, and perhaps size as well.

int main(int argc, char ** argv) {
  QApplication a{argc, argv};
  QSplashScreen splash;
  QLabel image{&splash};
  image.move(50, 50);
  ...
  splash.show();
  return a.exec();
}

Upvotes: 5

Jatin
Jatin

Reputation: 286

Much the same as Kuba Ober's above code with some minor but necessary additions.

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

Upvotes: 2

Related Questions