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 Center a Window on the Screen

How to Center a Window on the Screen

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.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.
  • G Offline
    G Offline
    gapry
    wrote on last edited by
    #1

    Development Environment

    1. Linux Y410P 4.14.71-1-MANJARO #1 SMP PREEMPT x86_64 GNU/Linux
    2. Qt Creator 4.7.0
    3. Based on Qt 5.11.1 (GCC 8.2.0, 64 bit)

    I use the wiki approach[1] to center the window which is a QWidget on the screen and Qt Creator show the following warning message.

    'availableGeometry' is deprecated: Use QGuiApplication::screens()
    

    I check the official document[2] and find QGuiApplication::screens() will return QList<QScreen *>.

    According the document of QScreen Class [3], it provides geometry() to return QRect.

    So I try this code auto screenGeometry = QGuiApplication::screens().first()->geometry(); and it occurs the following error message.

    member access into incomplete type 'QScreen'
    

    And suggestion?

    Thanks

    References

    1. How to Center a Window on the Screen
    2. QList<QScreen *> QGuiApplication::screens()
    3. QScreen Class
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gapry said in How to Center a Window on the Screen:

      member access into incomplete type 'QScreen'

      QScreen is not known to the compiler (except that it knows that it's a class) - so you should include the header where the QScreen class is defined.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      SGaistS 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @gapry said in How to Center a Window on the Screen:

        member access into incomplete type 'QScreen'

        QScreen is not known to the compiler (except that it knows that it's a class) - so you should include the header where the QScreen class is defined.

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        @Christian-Ehrlicher said in How to Center a Window on the Screen:

        @gapry said in How to Center a Window on the Screen:

        member access into incomplete type 'QScreen'

        QScreen is not known to the compiler (except that it knows that it's a class) - so you should include the header where the QScreen class is defined.

        @Christian-Ehrlicher Didn't you mean where the QScreen class is used in your application ?

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

        Christian EhrlicherC 1 Reply Last reply
        1
        • G Offline
          G Offline
          gapry
          wrote on last edited by
          #4

          Well, I make a idiot mistake. I forget do this #include <QScreen>.

          It can solve the issue. Thank you.

          1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            @Christian-Ehrlicher said in How to Center a Window on the Screen:

            @gapry said in How to Center a Window on the Screen:

            member access into incomplete type 'QScreen'

            QScreen is not known to the compiler (except that it knows that it's a class) - so you should include the header where the QScreen class is defined.

            @Christian-Ehrlicher Didn't you mean where the QScreen class is used in your application ?

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #5

            @SGaist said in How to Center a Window on the Screen:

            where the QScreen class is used in your application

            Yes :)

            @gapry : Please mark the thread as fixed

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            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