Commit 0855d4ac authored by Eike Ziller's avatar Eike Ziller

Workaround QCompleter issue with closing its popup on escape

QCompleter doesn't close its popup if there's a application wide
'escape' shortcut.
This commit adds the necessary shortcut overrides for CompletingTextEdit
and FancyLineEdit, which fixes the issue at least for find tool bar,
advanced search, gerrit dialog and description field of submit editor.

Task-number: QTCREATORBUG-9453
Change-Id: Ib1df218ab6b9a54fbf19d6132c6edd8e83ace46c
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 1fd1bf98
...@@ -190,6 +190,20 @@ void CompletingTextEdit::focusInEvent(QFocusEvent *e) ...@@ -190,6 +190,20 @@ void CompletingTextEdit::focusInEvent(QFocusEvent *e)
QTextEdit::focusInEvent(e); QTextEdit::focusInEvent(e);
} }
bool CompletingTextEdit::event(QEvent *e)
{
// workaround for QTCREATORBUG-9453
if (e->type() == QEvent::ShortcutOverride && completer()
&& completer()->popup() && completer()->popup()->isVisible()) {
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
ke->accept();
return true;
}
}
return QTextEdit::event(e);
}
} // namespace Utils } // namespace Utils
#include "moc_completingtextedit.cpp" #include "moc_completingtextedit.cpp"
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QCompleter; class QCompleter;
class QEvent;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils { namespace Utils {
...@@ -59,6 +60,7 @@ public: ...@@ -59,6 +60,7 @@ public:
protected: protected:
void keyPressEvent(QKeyEvent *e); void keyPressEvent(QKeyEvent *e);
void focusInEvent(QFocusEvent *e); void focusInEvent(QFocusEvent *e);
bool event(QEvent *e);
private: private:
class CompletingTextEditPrivate *d; class CompletingTextEditPrivate *d;
......
...@@ -31,13 +31,15 @@ ...@@ -31,13 +31,15 @@
#include "historycompleter.h" #include "historycompleter.h"
#include "qtcassert.h" #include "qtcassert.h"
#include <QDebug> #include <QAbstractItemView>
#include <QPropertyAnimation>
#include <QApplication> #include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QPainter> #include <QPainter>
#include <QPropertyAnimation>
#include <QStyle> #include <QStyle>
#include <QDesktopWidget>
/*! Opens a menu at the specified widget position. /*! Opens a menu at the specified widget position.
* This functions computes the position where to show the menu, and opens it with * This functions computes the position where to show the menu, and opens it with
...@@ -251,6 +253,20 @@ void FancyLineEdit::resizeEvent(QResizeEvent *) ...@@ -251,6 +253,20 @@ void FancyLineEdit::resizeEvent(QResizeEvent *)
updateButtonPositions(); updateButtonPositions();
} }
bool FancyLineEdit::event(QEvent *e)
{
// workaround for QTCREATORBUG-9453
if (e->type() == QEvent::ShortcutOverride && completer()
&& completer()->popup() && completer()->popup()->isVisible()) {
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
ke->accept();
return true;
}
}
return QLineEdit::event(e);
}
void FancyLineEdit::setButtonPixmap(Side side, const QPixmap &buttonPixmap) void FancyLineEdit::setButtonPixmap(Side side, const QPixmap &buttonPixmap)
{ {
d->m_iconbutton[side]->setPixmap(buttonPixmap); d->m_iconbutton[side]->setPixmap(buttonPixmap);
......
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
#include <QLineEdit> #include <QLineEdit>
#include <QAbstractButton> #include <QAbstractButton>
QT_BEGIN_NAMESPACE
class QEvent;
QT_END_NAMESPACE
namespace Utils { namespace Utils {
class FancyLineEditPrivate; class FancyLineEditPrivate;
...@@ -109,7 +113,8 @@ private slots: ...@@ -109,7 +113,8 @@ private slots:
void iconClicked(); void iconClicked();
protected: protected:
virtual void resizeEvent(QResizeEvent *e); void resizeEvent(QResizeEvent *e);
bool event(QEvent *e);
private: private:
// Unimplemented, to force the user to make a decision on // Unimplemented, to force the user to make a decision on
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment