如何正确恢复窗口7/vista aero快照调整大小的窗口小部件
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
}
相关文章:
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- GTK3 检测用户大小调整窗口
- Wxwidgets - 如何添加调整大小事件处理程序以使"X"绘图随窗口调整大小?
- 尝试在 win 32 中禁用窗口大小调整时,窗口样式行为不一致
- QGraphics手动调整窗口大小后场景宽度/高度没有变化
- Qt - 防止在拖动标题栏时调整窗口大小
- 在使用 resizeEvent 调整窗口大小时调整 Qlabel 图像的大小
- 在 Direct2D 绘图中,调整窗口大小后尺寸会更改
- 如何让用户垂直调整大小窗口
- win32 自动调整父窗口的大小以适合其内容
- WinAPI.检查窗口大小调整是否已完成
- QQuickView窗口在调整鼠标大小时冻结
- 如何设置启用setFixize后再次调整主窗口大小
- C++MFC按钮在窗口调整大小时消失
- Buit矩形(我自己的类型),不会随窗口调整大小
- 当GLFW窗口调整大小时,渲染区域不会改变
- 根据窗口调整QLabel内的QPixmap的大小
- GLFW轮询等待窗口调整完成,如何修复
- 在win32 api c中使用窗口调整文本框大小
- 如果在父窗口调整大小期间打开,子窗口将冻结