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. How to CenterScreen the Application?
QtWS25 Last Chance

How to CenterScreen the Application?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 6.9k 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.
  • K Offline
    K Offline
    khalidmushtaq65
    wrote on last edited by
    #1

    Hi,

    I am new to QT and developing an Application in QT, found it too exciting:-)

    I just want to know how to start the application windows on the center of screen, tried a lot but couldn't get through.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mazur
      wrote on last edited by
      #2

      Try this:

      @QRect frect = frameGeometry();
      frect.moveCenter(QDesktopWidget().availableGeometry().center());
      move(frect.topLeft());@

      http://darkmind2007.blogspot.com/2009/10/qt-window-in-center-of-screen.html

      Works for me and as far as I know there is no function in Qt which can center window so you can use this solution above.

      delete this->signature;

      1 Reply Last reply
      1
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        @
        window->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, window->size(), qApp->desktop()->availableGeometry()));
        @

        It's a common issue.

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          [quote author="peppe" date="1295841691"]@
          window->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, window->size(), qApp->desktop()->availableGeometry()));
          @

          It's a common issue.[/quote]

          Now you can point to this "wiki article":http://developer.qt.nokia.com/wiki/Center_a_Window_on_the_Screen in the future :-)

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • K Offline
            K Offline
            khalidmushtaq65
            wrote on last edited by
            #5

            Thanks for the reply.

            @Mazur.. It's not working. showing 'frameGeometry() not defined' and 'move not defined'.

            @peppe.. it also shows error 'Invalid struct QStyle'

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Then you will have to

              @
              #include <QStyle>
              #include <QDesktopWidget>
              @

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • K Offline
                K Offline
                khalidmushtaq65
                wrote on last edited by
                #7

                Thanks Volker.

                It's working now:-)

                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