Skip to content

Commit 6af8ea8

Browse files
committed
fix QScreen::grabWindow bbehaving weirdly
maybe it's just on mac
1 parent 0fec164 commit 6af8ea8

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/app/qgsappscreenshots.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <QWindow>
1919
#include <QScreen>
2020
#include <QImageWriter>
21+
#include <QTransform>
2122

2223
#include "qgsappscreenshots.h"
2324

@@ -38,10 +39,7 @@ QgsAppScreenShots::QgsAppScreenShots( const QString &saveDirectory )
3839
void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, GrabMode mode )
3940
{
4041
QPixmap pix;
41-
int x = 0;
42-
int y = 0;
43-
int w = -1;
44-
int h = -1;
42+
QRect geom;
4543

4644
QScreen *scr = screen( widget );
4745
if ( widget )
@@ -53,18 +51,21 @@ void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, Gr
5351
}
5452
else if ( mode == GrabWidgetAndFrame )
5553
{
56-
const QRect geom = widget->frameGeometry();
57-
QPoint tl = geom.topLeft();
58-
x = tl.x();
59-
y = tl.y();
60-
w = geom.width();
61-
h = geom.height();
54+
geom = widget->frameGeometry();
6255
}
6356
}
6457
if ( !widget || mode != GrabWidget )
6558
{
6659
WId wid = widget ? widget->winId() : 0;
67-
pix = scr->grabWindow( wid, x, y, w, h );
60+
pix = scr->grabWindow( wid );
61+
if ( !geom.isEmpty() )
62+
{
63+
qreal dpr = scr->devicePixelRatio();
64+
pix = pix.copy( static_cast<int>( geom.x() * dpr ),
65+
static_cast<int>( geom.y() * dpr ),
66+
static_cast<int>( geom.width() * dpr ),
67+
static_cast<int>( geom.height() * dpr ) );
68+
}
6869
}
6970

7071
const QString &fileName = mSaveDirectory + "/" + name + ".png";

0 commit comments

Comments
 (0)