Qt: Fix some focus crashes

This commit is contained in:
Jeffrey Pfau 2016-01-18 19:36:13 -08:00
parent 13dfb144e8
commit 17d343656f
3 changed files with 11 additions and 4 deletions

View File

@ -81,9 +81,10 @@ void SensorView::jiggerer(QAbstractButton* button, void (InputController::*sette
}
bool SensorView::event(QEvent* event) {
if (event->type() == QEvent::WindowActivate) {
QEvent::Type type = event->type();
if (type == QEvent::WindowActivate || type == QEvent::Show) {
m_input->stealFocus(this);
} else if (event->type() == QEvent::WindowDeactivate) {
} else if (type == QEvent::WindowDeactivate || type == QEvent::Hide) {
m_input->releaseFocus(this);
}
return QWidget::event(event);

View File

@ -37,6 +37,10 @@ ShortcutView::ShortcutView(QWidget* parent)
connect(m_ui.clearButton, SIGNAL(clicked()), this, SLOT(clear()));
}
ShortcutView::~ShortcutView() {
m_input->releaseFocus(this);
}
void ShortcutView::setController(ShortcutController* controller) {
m_controller = controller;
m_ui.shortcutTable->setModel(controller);
@ -117,9 +121,10 @@ void ShortcutView::closeEvent(QCloseEvent*) {
bool ShortcutView::event(QEvent* event) {
if (m_input) {
if (event->type() == QEvent::WindowActivate) {
QEvent::Type type = event->type();
if (type == QEvent::WindowActivate || type == QEvent::Show) {
m_input->stealFocus(this);
} else if (event->type() == QEvent::WindowDeactivate) {
} else if (type == QEvent::WindowDeactivate || type == QEvent::Hide) {
m_input->releaseFocus(this);
}
}

View File

@ -22,6 +22,7 @@ Q_OBJECT
public:
ShortcutView(QWidget* parent = nullptr);
~ShortcutView();
void setController(ShortcutController* controller);
void setInputController(InputController* input);