Skip to content

Commit

Permalink
fix QScreen::grabWindow bbehaving weirdly
Browse files Browse the repository at this point in the history
maybe it's just on mac
  • Loading branch information
3nids committed Oct 4, 2018
1 parent 0fec164 commit 6af8ea8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/app/qgsappscreenshots.cpp
Expand Up @@ -18,6 +18,7 @@
#include <QWindow>
#include <QScreen>
#include <QImageWriter>
#include <QTransform>

#include "qgsappscreenshots.h"

Expand All @@ -38,10 +39,7 @@ QgsAppScreenShots::QgsAppScreenShots( const QString &saveDirectory )
void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, GrabMode mode )
{
QPixmap pix;
int x = 0;
int y = 0;
int w = -1;
int h = -1;
QRect geom;

QScreen *scr = screen( widget );
if ( widget )
Expand All @@ -53,18 +51,21 @@ void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, Gr
}
else if ( mode == GrabWidgetAndFrame )
{
const QRect geom = widget->frameGeometry();
QPoint tl = geom.topLeft();
x = tl.x();
y = tl.y();
w = geom.width();
h = geom.height();
geom = widget->frameGeometry();
}
}
if ( !widget || mode != GrabWidget )
{
WId wid = widget ? widget->winId() : 0;
pix = scr->grabWindow( wid, x, y, w, h );
pix = scr->grabWindow( wid );
if ( !geom.isEmpty() )
{
qreal dpr = scr->devicePixelRatio();
pix = pix.copy( static_cast<int>( geom.x() * dpr ),
static_cast<int>( geom.y() * dpr ),
static_cast<int>( geom.width() * dpr ),
static_cast<int>( geom.height() * dpr ) );
}
}

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

0 comments on commit 6af8ea8

Please sign in to comment.