[PyQt] Create a class to position a window on the screen.

Hans-Peter Jansen hpj at urpla.net
Sun Jan 9 12:57:23 GMT 2011


Rohit,

you might want to generally abandon this html junk in mailing lists to 
actually _raise_ your professionality score [and the is my last reply 
to an inquiry in such a form of you].

On Sunday 09 January 2011, 03:23:01 Rohit Coder wrote:
> Hi,elementFontfont-familyfont-sizefont-stylefont-variantfont-weightle
>tter-spacingline-heighttext-decorationtext-aligntext-indenttext-transf
>ormwhite-spaceword-spacingcolorBackgroundbg-attachmentbg-colorbg-image
>bg-positionbg-repeatBoxwidthheightborder-topborder-rightborder-bottomb
>order-leftmarginpaddingmax-heightmin-heightmax-widthmin-widthoutline-c
>oloroutline-styleoutline-widthPositioningpositiontopbottomrightleftflo
>atdisplayclearz-indexListlist-style-imagelist-style-typelist-style-pos
>itionTablevertical-alignborder-collapseborder-spacingcaption-sideempty
>-cellstable-layoutEffectstext-shadow-webkit-box-shadowborder-radiusOth
>eroverflowcursorvisibility I am new to Python and this is my fist 
> Python class. I am using PyQt4 framework on Windows 7. I don't know
> whether the code below is correctly written or not. I want to modify
> it further as: 1. In the arguments, I want to pass the name of 
> another opened Window (.py) on the screen.

Hmm, is that a window of your own application, or an arbitrary window on 
the desktop, IOW, what is the type if the windowName parameter?

> 2. I want to pass the 
> x-coord., y-coord. and the name of the window to position on the
> screen. How to modify the code to fulfill these requirements?
> **Attempted Code**
>     class PositionWindow:        def __init__(self, xCoord, yCoord,
> windowName, parent = None):          self.x = xCoord          self.y
> = yCoord          self.wName = windowName;                    def
> center(self):            screen =
> QtGui.QDesktopWidget().screenGeometry()            size =
> self.geometry()            self.move((screen.width()-size.width())/2,
> (screen.height()-size.height())/2) ...................Rohit.

You already found code to center your window on the desktop. Centering a 
window on another is archived conveniently by providing the parent 
window object as the parent parameter, btw.

Pete


More information about the PyQt mailing list