QSplashScreen doens't appear in the center when using setupUi
-
Hello everyone!
I'm in trouble with QSplashScreen-based class position when using
ui.setupUi(this)
. Everything's fine when I only set the pixmap, when I set both pixmap and the form, or only the form, the position is not centered as well (so for me the position of splash screen is different for all the three cases). OS Win10, Qt 6.3.2.
Triedthis->move(screen()->availableGeometry().center())
in different places, not only in the constructor, but it had no effect.Does anyone know how do I center the splash screen with the form?
My code is extremely simple:
CSplash::CSplash() : QSplashScreen() { ui.setupUi(this); this->move(screen()->availableGeometry().center()); } //... int main(int argc, char *argv[]) { QApplication a(argc, argv); CSplash splash{}; splash.show(); MainWindow w; w.show(); splash.finish(&w); return a.exec(); }
And I haven't set the position in the form itself:
-
@bibasmall said in QSplashScreen doens't appear in the center when using setupUi:
Tried this->move(screen()->availableGeometry().center()) in different places, not only in the constructor, but it had no effect.
move()
gets as input a coordinate which is used for the upper left corner of your widget. If you use the center of the available screen geometry this means that your widget is position bottom right of the center. Instead, you need to subtract half the width of your splashscreen for the x coordinate and half the height for the y coordinate. This only can be done after Qt has calculated the widget's size which happens with a call toshow()
. So, firstshow()
and only thenmove()
. -
Hi,
What exactly is your goal ? QSplashScreen is a ready made widget that already contains logic to show pixmap and messages. If you want more, you should rather re-implement the drawContents method.
-
@bibasmall said in QSplashScreen doens't appear in the center when using setupUi:
Tried this->move(screen()->availableGeometry().center()) in different places, not only in the constructor, but it had no effect.
move()
gets as input a coordinate which is used for the upper left corner of your widget. If you use the center of the available screen geometry this means that your widget is position bottom right of the center. Instead, you need to subtract half the width of your splashscreen for the x coordinate and half the height for the y coordinate. This only can be done after Qt has calculated the widget's size which happens with a call toshow()
. So, firstshow()
and only thenmove()
. -