PySide moving one window to the screen location of another window - pyside

I would like to get the screen location of one window, and then take those coordinates and move another window to that location. Thanks.

Just for the position, you can get the position of the first window:
pos = self.first.pos().toTuple()
and move the second one there:
self.second.move(*pos)
You can do the same with its size:
size = self.first.size().toTuple()
self.second.resize(*size)

Related

How to stick window to left half part of screen?

I am using xlib to set window to certain position using XMoveResizeWindow function
All works fine, but when I want to 'stick' my window to left part of screen, I get the wrong position and size: there is a space between window and left, top and bottom screen borders.
To find out 'right' coords & dimensions of window stuck to left manually, I have written a watcher program which continuously calls XGetGeometry and prints results to screen, so I got these results of a 'stuck' window:
X: -40
Y: 14
W: 2000
H: 2426
When I pass these values to XMoveResizeWindow function, I still get the wrong position.
I have extended my watcher program to print all available properties of the window to see which will be changed when I manually 'stick' the window, but nothing changed except max_width and max_height fields of WM_NORMAL_HINTS property.
If you have an idea what am I doing wrong, please let me know.

How to get window original size and position (wsNormal vs wsMaximized)

I'm looking to store user personalization of window size and position to use it when the application is reopened. That's actually very simple and I have the following code working:
OnCreate:
Width := wIni.ReadInteger('FORM', 'FORMW', 980);
Height := wIni.ReadInteger('FORM', 'FORMH', 500);
PnlXMLI.Width := wIni.ReadInteger('FORM', 'PNLXMLIW', 500);
WindowState := TWindowState(GetEnumValue(TypeInfo(TWindowState), wIni.ReadString('FORM', 'WINDOWSTATE', 'wsNormal')));
OnDestroy:
wIni.WriteInteger('FORM', 'FORMW', Width);
wIni.WriteInteger('FORM', 'FORMH', Height);
wIni.WriteInteger('FORM', 'PNLXMLIW', PnlXMLI.Width);
wIni.WriteString('FORM', 'WINDOWSTATE', GetEnumName(TypeInfo(TWindowState), Ord(WindowState)));
The problem is that when the user maximizes the window, and then restore it, it goes back to the size it was before maximizing. But if he maximizes, and then close and reopen the application and restore it, the application will not go back to original size before maximizing. It will be at the size of screen, because Width and Height properties gives the maximized size when read.
Question is: how can I get the original size of the window, i.e., the one it will go back to when the user restore the window? I tried setting WindowState to wsNormal right before reading the Width and Height, but it didn't work (maybe because the form is being destroyed?)... and I'd rather use a solution that doesn't do unnecessary GUI operations (for source code aesthetic reasons).
Thanks in advance.
The functions that you need are GetWindowPlacement and SetWindowPlacement. These operate on the WINDOWPLACEMENT struct. That struct has the rcNormalPosition member which is documented like this:
The window's coordinates when the window is in the restored position.
When you save away the window position and size you need to save away the values found in rcNormalPosition. In the opposite direction, when restoring the window position and size you must call SetWindowPlacement passing as rcNormalPosition the value stored in the user preference in the INI file.

How do I change the viewport of a window in win32?

I have a window with child windows inside in it. The child windows take up about 1000 pixels of vertical space. However, our users don't always have 1000 pixels of vertical space available - they might have as little as 500 or 600 pixels.
I want to be able to display this window at a size of 500 pixels high, and have the user "scroll" up and down the window to see the full contents. The window should always be 500 pixels high, but the view within it should change.
Assume I can add a scroll bar somewhere so the user can choose which part of the window he wants to see. Windows will normally paint the window contents from height 0 to height 500; how do I tell it instead to "paint from height 250 to height 750", for example?
I know that I can set the viewport with functions like SetViewportOrgEx etc, but those functions require a device context - when do I call them if I want them to be "permanent"? Do I call them when I get the WM_PAINT message from windows? Or at some other time? And which functions from that family do I want to use?
Edit to add: I don't want to actually change the position of the child windows - they should stay at the same position, and the only thing that should change is the view into the window.
Thanks.
If (when you get messages about the scroll bars changing) you call ScrollWindowEx with the SW_SCROLLCHILDREN flag, the child windows should be told to scroll along with everything else. This ought to put them in the right position.

Window size store so that next time when opened it is the same as before

I have a window(MDI ) create,when it is opened by application,i will increase it size by dragging,and close it.so next time if i open it,the size has to new one.Values have to be stored in INI,i know this,but how to get the exact coordinates so that it can used later to open it
The window object should have the following properties:
Top
Left
Height
Width

How can I position QDockWidgets as the screen shot shows using code?

I want a Qt window to come up with the following arrangement of dock widgets on the right.
alt text http://img72.imageshack.us/img72/6180/docksonside.png
Qt allows you to provide an argument to the addDockWidget method of QMainWindow to specify the position (top, bottom, left or right) but apparently not how two QDockWidgets placed on the same side will be arranged.
Here is the code that adds the dock widgets. this uses PyQt4 but it should be the same for Qt with C++
self.memUseGraph = mem_use_widget(self)
self.memUseDock = QDockWidget("Memory Usage")
self.memUseDock.setObjectName("Memory Usage")
self.memUseDock.setWidget(self.memUseGraph)
self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.memUseDock)
self.diskUsageGraph = disk_usage_widget(self)
self.diskUsageDock = QDockWidget("Disk Usage")
self.diskUsageDock.setObjectName("Disk Usage")
self.diskUsageDock.setWidget(self.diskUsageGraph)
self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.diskUsageDock)
When this code is used to add both of them to the right side, one is above the other, not like the screen shot I made. The way I made that shot was to drag them there with the mouse after starting the program, but I need it to start that way.
You can use QMainWindow::splitDockWidget .
From the docs:
Splits the space covered by the first dock widget into two parts, moves the first dock widget into the first part, and moves the second dock widget into the second part.
The orientation specifies how the space is divided: A Qt::Horizontal split places the second dock widget to the right of the first; a Qt::Vertical split places the second dock widget below the first.
You have to set QMainWindow::dockNestingEnabled to true first (but I guess you already did that).
I never tried it but I think you can set the orientation of the dock widget when adding it to the main window:
void QMainWindow::addDockWidget ( Qt::DockWidgetArea area, QDockWidget * dockwidget, Qt::Orientation orientation )

Resources