A bit about

Hello, everyone! All you can see below is just my bank of information. Some material I've found in the fathomless net, some I've learned myself. Don't think all of the information here is right or actual, but may be it could be of use for you :) All feedback is welcome, especially constructive ones :)

Thursday, October 22, 2009

QT: Window in the center of screen

The problem is how to position Qt windows in the center of screen. Found the solution here. It's a Russian site, but I hope the code is visible. There are just two similar codes for positioning. I liked the second one :) It's shorter and clearer.
QRect frect = frameGeometry();
frect.moveCenter(QDesktopWidget().availableGeometry().center());
move(frect.topLeft())

I assume that this code is placed inside a constructor of the window which is positioned.

6 comments:

  1. Thank you, I corrected a minor bug of mine, because I only cared about geometry, not frameGeometry.

    Unfortunately, this code does not work under Linux, because of frameGeometry problems. But this is an X11 problem which Qt cannot solve.

    ReplyDelete
  2. Thanks, it works fine!

    ReplyDelete
  3. For me, it works perfectly under Linux (Qt 4.7).

    Thanks a lot, that's the cleanest solution I've ever come across.

    ReplyDelete
  4. short and sweet :)
    thanks

    ReplyDelete
  5. when i open music media all of my music is gone!!! all 2000 plus songs. what hap pend to them?

    ReplyDelete
  6. I liked second option - works well in PyQt

    ReplyDelete