Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 0ef261c

Browse files
committed
QWidget *QDesktopWidget::screen(int) has been deprecated with no replacement
1 parent 4251790 commit 0ef261c

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/MainWindow.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <QFileSystemWatcher>
4444
#include <QDesktopWidget>
4545
#include <QMenu>
46+
#include <QScreen>
4647

4748
#include <cassert>
4849
#include <set>
@@ -257,8 +258,22 @@ MainWindow::MainWindow(QWidget* parent):
257258

258259
closeFile();
259260

260-
// start centered
261-
move(QApplication::desktop()->screen()->rect().center() - rect().center());
261+
/* start centered
262+
263+
As of https://codereview.qt.nokia.com/c/qt/qtbase/+/268417,
264+
QWidget *QDesktopWidget::screen(int) or Application::desktop()->screen() has been
265+
deprecated with no replacement. A replacement might be provided in QT6 which
266+
the following 4 lines of code should be re-evaluated if a replacement is provided.
267+
268+
The solution of the following 4 lines of code was indirectly provided by
269+
Riccardo Fagiolo in "window_main.cpp" at
270+
https://stackoverflow.com/questions/46300065/dynamically-resizing-two-qlabel-implementations
271+
*/
272+
QSize size = QGuiApplication::screens().at(0)->availableSize();
273+
int x = size.width() / 2 - width() / 2;
274+
int y = size.height() / 2 - height() / 2;
275+
move(x, y);
276+
// End stackoverflow provided code by Riccardo Fagiolo
262277

263278
QAction* genBashRemediation = new QAction("&bash", this);
264279
QObject::connect(

src/TailoringWindow.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <QTimer>
3737
#include <QDateTime>
3838
#include <QStack>
39+
#include <QScreen>
3940

4041
#include <algorithm>
4142
#include <cassert>
@@ -230,8 +231,22 @@ TailoringWindow::TailoringWindow(struct xccdf_policy* policy, struct xccdf_bench
230231
this, SLOT(searchNext())
231232
);
232233

233-
// start centered
234-
move(QApplication::desktop()->screen()->rect().center() - rect().center());
234+
/* start centered
235+
236+
As of https://codereview.qt.nokia.com/c/qt/qtbase/+/268417,
237+
QWidget *QDesktopWidget::screen(int) or Application::desktop()->screen() has been
238+
deprecated with no replacement. A replacement might be provided in QT6 which
239+
the following 4 lines of code should be re-evaluated if a replacement is provided.
240+
241+
The solution of the following 4 lines of code was indirectly provided by
242+
Riccardo Fagiolo in "window_main.cpp" at
243+
https://stackoverflow.com/questions/46300065/dynamically-resizing-two-qlabel-implementations
244+
*/
245+
QSize size = QGuiApplication::screens().at(0)->availableSize();
246+
int x = size.width() / 2 - width() / 2;
247+
int y = size.height() / 2 - height() / 2;
248+
move(x, y);
249+
// End stackoverflow provided code by Riccardo Fagiolo
235250
show();
236251
}
237252

0 commit comments

Comments
 (0)