Skip to content

Commit

Permalink
Ensure canvas has focus if nothing else has
Browse files Browse the repository at this point in the history
Forward port from Sourcepole's fork
  • Loading branch information
manisandro authored and nyalldawson committed Aug 21, 2017
1 parent 4c52607 commit a6b0c44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1234,6 +1234,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
}
#endif

connect( qApp, SIGNAL( focusChanged( QWidget*, QWidget* ) ), this, SLOT( onFocusChanged( QWidget*, QWidget* ) ) );
} // QgisApp ctor

QgisApp::QgisApp()
Expand Down Expand Up @@ -8791,6 +8792,15 @@ void QgisApp::userRotation()
mMapCanvas->refresh();
}

void QgisApp::onFocusChanged( QWidget* /*old*/, QWidget* now )
{
// If nothing has focus even though the window is active, ensure map canvas receives it
if ( !now && isActiveWindow() )
{
mapCanvas()->setFocus();
}
}

// toggle overview status
void QgisApp::isInOverview()
{
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1510,6 +1510,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void updateCrsStatusBar();

void onFocusChanged( QWidget* old, QWidget* now );

signals:

/**
Expand Down

3 comments on commit a6b0c44

@wonder-sk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @nyalldawson I have found out this commit breaks shift+drag of 3D view when the dock widget is docked - https://issues.qgis.org/issues/17337 - and I can't really see how to safely fix that while keeping the canvas auto-focus behavior. I am a bit worried that it may cause other similar issues in the future by forcing the focus to canvas. I would prefer to roll back this change to have modifier keys work correctly in 3D view...

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wonder-sk I'm ok for you to revert!

@manisandro you may want to revert from Kadas too

@manisandro
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson Thanks for the heads up, we haven't had any issues with it, and it is pretty essential for our "CAD"-style floating coordinate input widgets.

Please sign in to comment.