QT QMainWindow全屏几何图形,无框架尺寸

时间:2016-02-05 12:22:49

标签: c++ qt qmainwindow

我正在使用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'上设置几何1600x1172 + 0 + 0。产生的几何:1600x1150 + 0 + 22(框架:8,30,8,8,自定义边距:0,0,0,0,最小尺寸:780x539,最大尺寸:16777215x16777215)。

我不明白桌面()> availableGeometry返回的几何体看起来是不正确的。我的问题是,如何确定警告信息中显示的几何图形? (1600x1150 + 0 + 22)

1 个答案:

答案 0 :(得分:0)

我在这里找到答案: 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),窗口显示为预期。

相关问题