QT QMainWindow 全屏几何图形,没有帧大小

QT QMainWindow fullscreen geometry without frame size

本文关键字:QMainWindow 几何图形 QT      更新时间:2023-10-16

我正在使用MinGW为Windows 7构建QT应用程序。在我的代码中,我有一个从QMainWindow派生的类。此主窗口显示和关闭多次(在不同的屏幕上(。我使用以下代码显示窗口:

this->blockSignals(true);
this->close();
this->blockSignals(false);
this->showMaximized();
this->setGeometry(QApplication::desktop()->availableGeometry(mDisplayNumber));

仅在第一次执行此代码时,窗口才会按预期显示。下一次,窗口显示为最大化,但我在屏幕底部缺少几个像素。

执行

代码时,我还在 QT 中收到警告:

setGeometryDp:无法在 QWidgetWindow/'CDisplayClassWindow' 上设置 geometry 1600x1172+0+0。生成的几何体:1600x1150+0+22(帧:8、30、8、8,自定义边距:0、0、0、0,最小尺寸:780x539,最大尺寸:16777215x16777215(。

我不明白的是,desktop((>availableGeometry 返回的几何看起来不正确。我的问题是,如何确定警告消息中显示的几何形状?(1600×1150+0+22(

我在这里找到了答案:https://wiki.qt.io/How_to_Center_a_Window_on_the_Screen现在,我的 Show 函数如下:

Qt::WindowStates WindowState = this->windowState();
if(WindowState == Qt::WindowMaximized)
{
  this->setWindowState(WindowState ^ Qt::WindowMaximized);
}
this->setGeometry(
    QStyle::alignedRect(
        Qt::LeftToRight,
        Qt::AlignCenter,
        this->size(),
        QApplication::desktop()->availableGeometry(mDisplayNumber)));
this->showMaximized();

我仍然收到警告:setGeometryDp:无法在QWidgetWindow/'CDisplayClassWindow'上设置几何图形1600x1150+0+11。生成的几何体:1600x1150+0+22(帧:8、30、8、8,自定义边距:0、0、0、0,最小尺寸:780x539,最大尺寸:16777215x16777215(。

分辨率相同 (1600x1150(,窗口按预期显示。