Skip to content

Commit 28281ee

Browse files
committed
Set the background for layouts on the view, rather then in the scene
Setting the background on the scene means in applies in renders of the scene (e.g. to images). We don't want this - we always want scenes rendered on transparent backgrounds. So instead use stylesheets to only show the grey background outside of pages in the view.
1 parent fabfd77 commit 28281ee

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/core/layout/qgslayout.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ QgsLayout::QgsLayout( QgsProject *project )
2222
, mProject( project )
2323
, mPageCollection( new QgsLayoutPageCollection( this ) )
2424
{
25-
setBackgroundBrush( QColor( 215, 215, 215 ) );
25+
// just to make sure - this should be the default, but maybe it'll change in some future Qt version...
26+
setBackgroundBrush( Qt::NoBrush );
2627
}
2728

2829
void QgsLayout::initializeDefaults()

src/gui/layout/qgslayoutview.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
4040
setMouseTracking( true );
4141
viewport()->setMouseTracking( true );
4242

43+
// set the "scene" background on the view using stylesheets
44+
// we don't want to use QGraphicsScene::setBackgroundBrush because we want to keep
45+
// a transparent background for exports, and it's only a cosmetic thing for the view only
46+
// ALSO - only set it on the viewport - we don't want scrollbars/etc affected by this
47+
viewport()->setStyleSheet( QStringLiteral( "background-color:#d7d7d7;" ) );
48+
4349
mSpacePanTool = new QgsLayoutViewToolTemporaryKeyPan( this );
4450
mMidMouseButtonPanTool = new QgsLayoutViewToolTemporaryMousePan( this );
4551
mSpaceZoomTool = new QgsLayoutViewToolTemporaryKeyZoom( this );

0 commit comments

Comments
 (0)