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.
  • B Offline
    B Offline
    bibasmall
    wrote on 18 Apr 2023, 14:23 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 B 2 Replies Last reply 19 Apr 2023, 07:02
    0
    • B bibasmall
      18 Apr 2023, 14:23

      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 19 Apr 2023, 07:02 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
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 18 Apr 2023, 19:27 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

        B 1 Reply Last reply 18 Apr 2023, 20:21
        0
        • S SGaist
          18 Apr 2023, 19:27

          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.

          B Offline
          B Offline
          bibasmall
          wrote on 18 Apr 2023, 20:21 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
          • B bibasmall
            18 Apr 2023, 14:23

            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 19 Apr 2023, 07:02 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
            • B bibasmall has marked this topic as solved on 19 Apr 2023, 08:00
            • B bibasmall
              18 Apr 2023, 14:23

              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

              B Offline
              B Offline
              bibasmall
              wrote on 19 Apr 2023, 08:09 last edited by bibasmall
              #5

              @SimonSchroeder
              thank you, you were absolutely right.

              1 Reply Last reply
              0

              5/5

              19 Apr 2023, 08:09

              • Login

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