modify FramelessDelegateWin

This commit is contained in:
brige 2025-11-16 16:19:40 +08:00
parent 5367abc5e8
commit 9a24595873
3 changed files with 28 additions and 14 deletions

View File

@ -59,7 +59,9 @@ int main(int argc, char* argv[]) {
MainFrame mainWindow;
splash.showMessage(("正在创建主窗口..."), Qt::AlignHCenter | Qt::AlignBottom, Qt:: white);
// 先显示窗口,再在事件循环启动后最大化,避免首次显示时原生窗口放置未就绪导致尺寸异常
mainWindow.showMaximized();
// QTimer::singleShot(0, &mainWindow, &MainFrame::showMaximized);
splash.finish(&mainWindow);

View File

@ -114,7 +114,6 @@ bool OEScene::AddToScene(osg::Node* node) const {
}
void OEScene::SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint, double duration_s) {
return;
dyt_check(nullptr != earthManipulator_);
earthManipulator_->setViewpoint(viewpoint, duration_s);

View File

@ -162,19 +162,31 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
case WM_NCHITTEST: {
return OnNCTitTest(msg, result);
}
case WM_GETMINMAXINFO:
{
if (::IsZoomed(msg->hwnd)) {
RECT frame = { 0, 0, 0, 0 };
AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0);
double dpr = mainWidget_->devicePixelRatioF();
case WM_GETMINMAXINFO: {
// 使用工作区定义最大化位置与大小,避免遮挡任务栏
MINMAXINFO* mmi = reinterpret_cast<MINMAXINFO*>(msg->lParam);
HMONITOR monitor = MonitorFromWindow(msg->hwnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
::ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
if (monitor && GetMonitorInfo(monitor, &mi)) {
const RECT& work = mi.rcWork;
const RECT& rcMon = mi.rcMonitor;
mmi->ptMaxPosition.x = work.left;
mmi->ptMaxPosition.y = work.top;
mmi->ptMaxSize.x = work.right - work.left;
mmi->ptMaxSize.y = work.bottom - work.top;
// 限制拖动最大尺寸为监视器大小(非必须,但较合理)
mmi->ptMaxTrackSize.x = rcMon.right - rcMon.left;
mmi->ptMaxTrackSize.y = rcMon.bottom - rcMon.top;
}
// 最大化时不叠加系统边框内边距,避免左右出现可见空隙
if (::IsZoomed(msg->hwnd)) {
// 最大化时不叠加系统边框内边距
frames_.setLeft(0);
frames_.setTop(0);
frames_.setRight(0);
frames_.setBottom(0);
mainWidget_->setContentsMargins(margins_);
justMaximized_ = true;
} else {
@ -188,7 +200,8 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
if (nullptr != titleBar_ && flag) {
titleBar_->OnMaximized(justMaximized_);
}
return false;
*result = 0;
return true;
}
case WM_NCLBUTTONDBLCLK: {
*result = 0;
@ -212,13 +225,13 @@ bool FramelessDelegateWin::nativeEvent(const QByteArray & eventType, void* messa
void FramelessDelegateWin::OnShow() {
if (isFirstShow_) {
isFirstShow_ = false;
SetNativeWindowLong();
isFirstShow_ = false;
}
mainWidget_->setAttribute(Qt::WA_Resized);
if (!isFirstShow_ && mainWidget_->isMaximized()) {
// 仅当存在有效的窗口放置信息length 已设置)时才恢复窗口位置,避免首次显示使用未初始化的数据
if (!isFirstShow_ && mainWidget_->isMaximized() && wndPlaceMent_.length == sizeof(wndPlaceMent_)) {
QMetaObject::invokeMethod(
this,
[=]() {