Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How set QWidget top left cordinate?
Qt 6.12 LTS is out! See what's new in the release blog

How set QWidget top left cordinate?

Scheduled Pinned Locked Moved General and Desktop
qwidgetqpainter
11 Posts 5 Posters 7.5k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by
    #2

    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().

    I 1 Reply Last reply
    0
    • Chris KawaC Chris Kawa

      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().

      I Offline
      I Offline
      iRenji
      wrote on last edited by iRenji
      #3

      @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.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #4

        How did you "removed" non-client area? Please provide significant code if possible.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          iRenji
          wrote on last edited by
          #5

          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);
          }
          
          1 Reply Last reply
          0
          • L Offline
            L Offline
            LuGRU
            wrote on last edited by
            #6

            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

            I 1 Reply Last reply
            0
            • L LuGRU

              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

              I Offline
              I Offline
              iRenji
              wrote on last edited by
              #7

              @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.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rondog
                wrote on last edited by Rondog
                #8

                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?

                I 1 Reply Last reply
                1
                • R Rondog

                  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?

                  I Offline
                  I Offline
                  iRenji
                  wrote on last edited by
                  #9

                  @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.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Rondog
                    wrote on last edited by
                    #10

                    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.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      ambershark
                      wrote on last edited by
                      #11

                      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.

                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt
                      • Unsolved