[英]How to correctly restore widgets that are resized by windows 7/vista aero snap
Windows 7具有此功能,如果將窗口拖動到屏幕的一側,它將最大化以占用一半的空間。 我的問題是-我正在嘗試實現小部件的大小和位置的還原,並且當Windows 7“最大化”小部件時,qt仍返回其位置和大小, 就像仍然正常顯示一樣 ,即-完全不正確的位置和大小。
qt5中對此有任何控制權嗎? 我在文檔中的任何地方都找不到它,而且很奇怪
這基本上就是我最終要做的。 底部的“框架幾何”部分對於補償小部件的邊框似乎是必需的。
QT += gui-private
.pro文件中需要以下代碼才能正常工作
#include <WinUser.h>
#include <qpa/qplatformnativeinterface.h>
static QWindow* windowForWidget(const QWidget* widget)
{
QWindow* window = widget->windowHandle();
if (window)
return window;
const QWidget* nativeParent = widget->nativeParentWidget();
if (nativeParent)
return nativeParent->windowHandle();
return 0;
}
#include <QWindow>
static HWND getHWNDForWidget(const QWidget* widget)
{
QWindow* window = ::windowForWidget(widget);
if (window && window->handle())
{
QPlatformNativeInterface* natInterface = QGuiApplication::platformNativeInterface();
return static_cast<HWND>(natInterface->nativeResourceForWindow(QByteArrayLiteral("handle"), window));
}
return 0;
}
void SaveSize(QWidget* w)
{
QSize size;
QPoint pos;
RECT pRect = { 0 };
HWND hwnd = getHWNDForWidget(w);
GetWindowRect(hwnd, &pRect);
auto left = w->frameGeometry().left();
auto right = w->frameGeometry().right();
auto width = w->width();
pos.setX(pRect.left);
pos.setY(pRect.top);
size.setWidth(pRect.right - pRect.left - (right - left - width));
size.setHeight(pRect.bottom - pRect.top);
//.... the rest of the code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.