专业的编程技术博客社区

网站首页 > 博客文章 正文

Qt获取全屏(qt全屏后其它窗口无法弹出)

baijin 2025-06-09 20:03:52 博客文章 1 ℃ 0 评论


在 Qt 中,获取全屏的方法有以下几种:

  1. 使用 QScreen 类:通过 QApplication::screens() 方法获取所有屏幕,然后遍历每个屏幕,再调用其 geometry() 方法获取其矩形区域,即可得到全屏区域。
QList<QScreen*> screens = QApplication::screens();
QRect screenRect;
foreach(QScreen* screen, screens) {
    screenRect = screen->geometry();
    // ...
}
  1. 使用 QWidget 类:通过获取主窗口的宽度和高度即可得到全屏区域,这种方法要求主窗口必须是全屏状态,否则无法正确获取全屏区域。
int w = this->width();   // 窗口宽度
int h = this->height();  // 窗口高度
int dw = QApplication::desktop()->width();   // 屏幕宽度
int dh = QApplication::desktop()->height();  // 屏幕高度
QRect fullScreenRect(0, 0, dw, dh);           // 全屏矩形区域
  1. 使用 QDesktopWidget 类:通过获取屏幕的宽度和高度即可得到全屏区域,这种方法不需要主窗口处于全屏状态。
QDesktopWidget* desktopWidget = QApplication::desktop();
int w = desktopWidget->width();   // 屏幕宽度
int h = desktopWidget->height();  // 屏幕高度
QRect fullScreenRect(0, 0, w, h);  // 全屏矩形区域

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表