Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSplashScreen doens't appear in the center when using setupUi

QSplashScreen doens't appear in the center when using setupUi

Scheduled Pinned Locked Moved Solved General and Desktop
splashscreenpositionform
5 Posts 3 Posters 839 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • bibasmallB Offline
    bibasmallB Offline
    bibasmall
    wrote on last edited by bibasmall
    #1

    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.
    Tried this->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:

    c7106bd2-2f53-46a3-bba6-fdf2058c4f6f-image.png

    S bibasmallB 2 Replies Last reply
    0
    • bibasmallB bibasmall

      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.
      Tried this->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:

      c7106bd2-2f53-46a3-bba6-fdf2058c4f6f-image.png

      S Offline
      S Offline
      SimonSchroeder
      wrote on last edited by
      #4

      @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 to show(). So, first show() and only then move().

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        bibasmallB 1 Reply Last reply
        0
        • SGaistS SGaist

          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.

          bibasmallB Offline
          bibasmallB Offline
          bibasmall
          wrote on last edited by
          #3

          @SGaist
          Hello, my goal was to hide the logic of progress bar inside my class. And I also use the form.

          1 Reply Last reply
          0
          • bibasmallB bibasmall

            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.
            Tried this->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:

            c7106bd2-2f53-46a3-bba6-fdf2058c4f6f-image.png

            S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #4

            @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 to show(). So, first show() and only then move().

            1 Reply Last reply
            2
            • bibasmallB bibasmall has marked this topic as solved on
            • bibasmallB bibasmall

              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.
              Tried this->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:

              c7106bd2-2f53-46a3-bba6-fdf2058c4f6f-image.png

              bibasmallB Offline
              bibasmallB Offline
              bibasmall
              wrote on last edited by bibasmall
              #5

              @SimonSchroeder
              thank you, you were absolutely right.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved