Pyside moving the window to the middle of the screen

Source: Internet
Author: User

Due to the different size of the computer, the fixed parameters of the window position set on one machine tend to perform poorly on the other machine.

Here's an example of moving a window to the center of the screen

1 ImportSYS2  fromPysideImportQtgui3 4 5 classPyside_center (qtgui.qwidget):6 7     def __init__(self):8Super (Pyside_center, self).__init__()9 Ten Self.initui () One  A     defInitui (self): -         #Set Window Size -Self.resize (250, 150) the         #call your own method of writing center - Self.center () -         #Set Title -Self.setwindowtitle ('Center') + self.show () -  +     defCenter (self): A         #get the data for the window, PySide.QtCore.QRect atQR =self.framegeometry () -         #get the center point coordinates of a native visual window -CP =qtgui.qdesktopwidget (). Availablegeometry (). Center () -         #move the Qrect to the center point - Qr.movecenter (CP) -         #move the window itself to the center point using the position obtained by the simulated rectangle in Self.move (Qr.topleft ()) -  to  +  - defMain (): the  *App =qtgui.qapplication (SYS.ARGV) $ex =Pyside_center ()Panax Notoginseng Sys.exit (App.exec_ ()) -  the  + if __name__=='__main__': AMain ()

Pyside moving the window to the middle of the screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.