From facf6e4b595354f916edabd215b327196c111868 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 30 Jun 2014 18:20:17 -0300 Subject: Calendar widget should hide when clicking somewhere else This patch adds a event filter to hide the calendar widget when it loses focus Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/simplewidgets.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'qt-ui/simplewidgets.cpp') diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index 94670b04b..7da691d1b 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -297,8 +297,7 @@ DateWidget::DateWidget(QWidget *parent) : QWidget(parent), setDate(QDate::currentDate()); setMinimumSize(QSize(80,64)); setFocusPolicy(Qt::StrongFocus); - calendarWidget->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - calendarWidget->setWindowModality(Qt::ApplicationModal); + calendarWidget->setWindowFlags(Qt::FramelessWindowHint); calendarWidget->setFirstDayOfWeek(getLocale().firstDayOfWeek()); calendarWidget->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader); @@ -306,8 +305,19 @@ DateWidget::DateWidget(QWidget *parent) : QWidget(parent), connect(calendarWidget, SIGNAL(clicked(QDate)), calendarWidget, SLOT(hide())); connect(calendarWidget, SIGNAL(activated(QDate)), this, SLOT(setDate(QDate))); connect(calendarWidget, SIGNAL(clicked(QDate)), this, SLOT(setDate(QDate))); + calendarWidget->installEventFilter(this); } +bool DateWidget::eventFilter(QObject *object, QEvent *event) +{ + if(event->type() == QEvent::FocusOut){ + calendarWidget->hide(); + return true; + } + return QObject::eventFilter(object, event); +} + + void DateWidget::setDate(const QDate& date) { mDate = date; @@ -367,6 +377,8 @@ void DateWidget::mousePressEvent(QMouseEvent *event) { calendarWidget->move(event->globalPos()); calendarWidget->show(); + calendarWidget->raise(); + calendarWidget->setFocus(); } void DateWidget::focusInEvent(QFocusEvent *event) -- cgit v1.2.3-70-g09d2