How set QWidget top left cordinate?
-
hello every one.
I have problem with QWidget painting.
I had need to manipulate title bar so i remove the non client area and add my title bar there.
after that when i run my app , qwidget start drow from ( 0 , 0) position of my window , and it,s have conflict with my title bar. i need to transform QWidget (0,0) coordinate , and i dont know how.
Could you help me to solve this problem? Thanks very much! -
Hi, welcome to devnet.
I don't quite understand your question. Do you want to move the window? If so then you can use move() or setGeometry().
-
@Chris-Kawa Tnx
http://i.imgur.com/sOJIBDP.png
in normal state QWidget start drawing from blue point in picture but i remove Non Client area and my QWidget start drawing from red point, you can see white space in bottom of window.
I need transform the QWidget content to blue point again. -
How did you "removed" non-client area? Please provide significant code if possible.
-
this is part of my code in nativeEvent :
if (message == WM_ACTIVATE)
{
MARGINS margins;margins.cxLeftWidth = 0;// LEFTEXTENDWIDTH; margins.cxRightWidth = 0; //RIGHTEXTENDWIDTH; margins.cyBottomHeight = 0;// BOTTOMEXTENDWIDTH; margins.cyTopHeight = TOPEXTENDWIDTH; WTA_OPTIONS ops; ops.dwFlags = WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON; ops.dwMask = WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON; SetWindowThemeNonClientAttributes(hWnd, ops.dwMask, ops.dwFlags); hr = DwmExtendFrameIntoClientArea(hWnd, &margins); lRet = 0; retvalue = true; } else if (message == WM_CREATE) { RECT rcClient; GetWindowRect(hWnd, &rcClient); // Inform the application of the frame change. SetWindowPos(hWnd, NULL, rcClient.left, rcClient.top, abs(rcClient.right-rcClient.left), abs(rcClient.top-rcClient.bottom), SWP_FRAMECHANGED); fCallDWP = true; lRet = 0; } else if (message == WM_NCCALCSIZE && wParam == true) { // Calculate new NCCALCSIZE_PARAMS based on custom NCA inset. NCCALCSIZE_PARAMS *pncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam); //Controlling Client frame pncsp->rgrc[0].left = pncsp->rgrc[0].left + 7; pncsp->rgrc[0].top = pncsp->rgrc[0].top ; pncsp->rgrc[0].right = pncsp->rgrc[0].right - 7; pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom - 7; pMessage->message = WM_NCCALCSIZE; lRet = 0; // No need to pass the message on to the DefWindowProc. fCallDWP = false; retvalue = true; } else if (WM_PAINT) { drawFrameTitle(hWnd); }
-
Hi,
First of all this issue has nothing to do with Qt.
Issue:
GetWindowRect - retrieve rect for Window
What You are looking for is GetClientRect -
@LuGRU thank for your answer , but that,s not issue
In WM_PAINT i just draw the title bar , not widget content .
I dont paint the gray part in that position, QWidget painter do that . i think maybe i can access to the painter that draw the gray part and transform to blue point. -
If I understand properly you are creating a window without a caption then drawing the caption inside the client area. Your upper left drawing coordinate would be the upper left corner of the window frame since the window frame is now inside the client area. Everything sounds like it is working properly.
Another way to draw a custom title bar in Win32 is something like this method: http://www.catch22.net/tuts/custom-titlebar You can add anything you want or custom draw it anyway you wish. This would not interfere with the location of the client area that you draw to for the rest of the program. I did this to all my windows stuff long time ago (the idea was from the link I attached). It got old after a few years and then I gave it up completely after a while.
If you are hooking into the native message loop you should be aware that the program will no longer be cross platform compatible. Is it worth it?
-
@Rondog Yes, that what i mean.
I see that link and as i understand aero desktop use DWM ( Desktop windows maneger ) can not do by that way.
So is there any qt trick to change the upper left coordinate. -
Your sample code is all classic Win32 API. Whatever method you develop this will run on any version of Windows. I checked on the old programs where I draw a custom title bar and it still works properly on Windows 7 X86_64. I am not sure why you think it won't work with the aero desktop window manager.
I don't know of a method to change the viewport of your application to modify the upper left corner location of the client area. You might end up having to modify the Qt sources to make this work if you want to go this route.
Another option that might work would be to create two widgets; one for the upper section containing the window caption and the lower for drawing. You can set the margin spacing to zero so there is no gap between the widgets and the parent frame and the two will look connected. When you draw in the lower widget the upper left corner of the client area will be 0,0.
-
Perhaps this will help:
http://doc.qt.io/qt-5/application-windows.html#window-geometry
This covers exactly what you are looking for. The difference between geometry that includes the titlebar and just the client area.