Difference between revisions of "How to Center a Window on the Screen"

From Qt Wiki
Jump to: navigation, search
(Cleanup)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{LangSwitch}}
 
[[Category:snippets]]
 
[[Category:snippets]]
 +
<code>
 +
#include <QStyle>
 +
#include <QDesktopWidget>
  
'''English''' | [[Center_a_Window_on_the_Screen_German|Deutsch]] | [[Center_a_Window_on_the_Screen_Bulgarian|Български]] | [[Center_a_Window_on_the_Screen_Korean|한국어]]
+
window->setGeometry(
 
+
    QStyle::alignedRect(
= How to center a window on the screen =
+
        Qt::LeftToRight,
 
+
        Qt::AlignCenter,
<code><br />#include &lt;QStyle&amp;gt;<br />#include &lt;QDesktopWidget&amp;gt;
+
        window->size(),
 
+
        qApp->desktop()->availableGeometry()
window-&gt;setGeometry(<br /> QStyle::alignedRect(<br /> Qt::LeftToRight,<br /> Qt::AlignCenter,<br /> window-&gt;size(),<br /> qApp-&gt;desktop()-&gt;availableGeometry()<br /> ));<br /></code>
+
    )
 +
);
 +
</code>

Latest revision as of 12:15, 28 June 2015

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

#include <QStyle>
#include <QDesktopWidget>

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