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?
Forum Updated to NodeBB v4.3 + New Features

How to CenterScreen the Application?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 6.9k Views 1 Watching
  • 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 24 Jan 2011, 00:17 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 24 Jan 2011, 00:51 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 24 Jan 2011, 04:01 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 24 Jan 2011, 11:17 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 24 Jan 2011, 13:00 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 24 Jan 2011, 13:36 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 24 Jan 2011, 15:35 last edited by
                #7

                Thanks Volker.

                It's working now:-)

                1 Reply Last reply
                0

                1/7

                24 Jan 2011, 00:17

                • Login

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