[Qt-interest] Centering the mainwindow

André Somers andre at familiesomers.nl
Fri Feb 20 22:05:55 CET 2009



"Stephen Jackson" <spjackson42 at gmail.com> schreef in bericht 
news:43fef2450902190326t13dce301qd7a822165222ee32 at mail.gmail.com...
> On Thu, Feb 19, 2009 at 9:04 AM, NARCISO, Rui wrote:
>>
>> Hi
>> How do I make it so that my MainWindow appears centered in the screen 
>> like the QSplashScreen does?
>>
>> Rui
>>
>
> Surely, if you look at the source of QSplashScreen you will find your 
> answer.

It is actually not all that obvious. I checked, and I could not find it in 
there.
So: some pointers for the TS then:
QDesktopWidget has a lot of useful properties, including things like "QRect 
screenGeometry()". To center your window, you can use your window's 
setGeometry or move methods. Note however that these refer to the upper left 
point of your window. A bit of adding and dividing is needed to get where 
you want, but that should not be too hard.

André 




More information about the Qt-interest-old mailing list