summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-02-15 01:00:50 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-02-15 01:00:51 +0100
commitef2ddcf551dec13215cb45cb000731f94b2f8e34 (patch)
treec8810f6ee77a81c3003ccc8783c9d3b17f0b8a5e /src/widgets
parente2cf6ade3535467bc2f21b54b82ed007d5ce279b (diff)
parent501cca2c4b0851cea7133ba56c3a05d71c25ce6d (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qwidget.cpp109
-rw-r--r--src/widgets/kernel/qwidget_p.h1
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp2
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp27
4 files changed, 73 insertions, 66 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index b91d637766..6a5f80f1ff 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -8298,49 +8298,57 @@ void QWidgetPrivate::hide_sys()
\endlist
*/
-
void QWidget::setVisible(bool visible)
{
- if (visible) { // show
- if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
- return;
+ if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) == !visible)
+ return;
- Q_D(QWidget);
+ // Remember that setVisible was called explicitly
+ setAttribute(Qt::WA_WState_ExplicitShowHide);
+
+ Q_D(QWidget);
+ d->setVisible(visible);
+}
+// This method is called from QWidgetWindow in response to QWindow::setVisible,
+// and should match the semantics of QWindow::setVisible. QWidget::setVisible on
+// the other hand keeps track of WA_WState_ExplicitShowHide in addition.
+void QWidgetPrivate::setVisible(bool visible)
+{
+ Q_Q(QWidget);
+ if (visible) { // show
// Designer uses a trick to make grabWidget work without showing
- if (!isWindow() && parentWidget() && parentWidget()->isVisible()
- && !parentWidget()->testAttribute(Qt::WA_WState_Created))
- parentWidget()->window()->d_func()->createRecursively();
+ if (!q->isWindow() && q->parentWidget() && q->parentWidget()->isVisible()
+ && !q->parentWidget()->testAttribute(Qt::WA_WState_Created))
+ q->parentWidget()->window()->d_func()->createRecursively();
//create toplevels but not children of non-visible parents
- QWidget *pw = parentWidget();
- if (!testAttribute(Qt::WA_WState_Created)
- && (isWindow() || pw->testAttribute(Qt::WA_WState_Created))) {
- create();
+ QWidget *pw = q->parentWidget();
+ if (!q->testAttribute(Qt::WA_WState_Created)
+ && (q->isWindow() || pw->testAttribute(Qt::WA_WState_Created))) {
+ q->create();
}
- bool wasResized = testAttribute(Qt::WA_Resized);
- Qt::WindowStates initialWindowState = windowState();
+ bool wasResized = q->testAttribute(Qt::WA_Resized);
+ Qt::WindowStates initialWindowState = q->windowState();
// polish if necessary
- ensurePolished();
+ q->ensurePolished();
- // remember that show was called explicitly
- setAttribute(Qt::WA_WState_ExplicitShowHide);
// whether we need to inform the parent widget immediately
- bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden);
+ bool needUpdateGeometry = !q->isWindow() && q->testAttribute(Qt::WA_WState_Hidden);
// we are no longer hidden
- setAttribute(Qt::WA_WState_Hidden, false);
+ q->setAttribute(Qt::WA_WState_Hidden, false);
if (needUpdateGeometry)
- d->updateGeometry_helper(true);
+ updateGeometry_helper(true);
// activate our layout before we and our children become visible
- if (d->layout)
- d->layout->activate();
+ if (layout)
+ layout->activate();
- if (!isWindow()) {
- QWidget *parent = parentWidget();
+ if (!q->isWindow()) {
+ QWidget *parent = q->parentWidget();
while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) {
parent->d_func()->layout->activate();
if (parent->isWindow())
@@ -8353,30 +8361,28 @@ void QWidget::setVisible(bool visible)
// adjust size if necessary
if (!wasResized
- && (isWindow() || !parentWidget()->d_func()->layout)) {
- if (isWindow()) {
- adjustSize();
- if (windowState() != initialWindowState)
- setWindowState(initialWindowState);
+ && (q->isWindow() || !q->parentWidget()->d_func()->layout)) {
+ if (q->isWindow()) {
+ q->adjustSize();
+ if (q->windowState() != initialWindowState)
+ q->setWindowState(initialWindowState);
} else {
- adjustSize();
+ q->adjustSize();
}
- setAttribute(Qt::WA_Resized, false);
+ q->setAttribute(Qt::WA_Resized, false);
}
- setAttribute(Qt::WA_KeyboardFocusChange, false);
+ q->setAttribute(Qt::WA_KeyboardFocusChange, false);
- if (isWindow() || parentWidget()->isVisible()) {
- d->show_helper();
+ if (q->isWindow() || q->parentWidget()->isVisible()) {
+ show_helper();
- qApp->d_func()->sendSyntheticEnterLeave(this);
+ qApp->d_func()->sendSyntheticEnterLeave(q);
}
QEvent showToParentEvent(QEvent::ShowToParent);
- QApplication::sendEvent(this, &showToParentEvent);
+ QApplication::sendEvent(q, &showToParentEvent);
} else { // hide
- if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
- return;
#if 0 // Used to be included in Qt4 for Q_WS_WIN
// reset WS_DISABLED style in a Blocked window
if(isWindow() && testAttribute(Qt::WA_WState_Created)
@@ -8387,33 +8393,30 @@ void QWidget::setVisible(bool visible)
SetWindowLong(winId(), GWL_STYLE, dwStyle);
}
#endif
- if (QApplicationPrivate::hidden_focus_widget == this)
+ if (QApplicationPrivate::hidden_focus_widget == q)
QApplicationPrivate::hidden_focus_widget = 0;
- Q_D(QWidget);
-
// hw: The test on getOpaqueRegion() needs to be more intelligent
// currently it doesn't work if the widget is hidden (the region will
// be clipped). The real check should be testing the cached region
// (and dirty flag) directly.
- if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty())
- parentWidget()->d_func()->setDirtyOpaqueRegion();
+ if (!q->isWindow() && q->parentWidget()) // && !d->getOpaqueRegion().isEmpty())
+ q->parentWidget()->d_func()->setDirtyOpaqueRegion();
- setAttribute(Qt::WA_WState_Hidden);
- setAttribute(Qt::WA_WState_ExplicitShowHide);
- if (testAttribute(Qt::WA_WState_Created))
- d->hide_helper();
+ q->setAttribute(Qt::WA_WState_Hidden);
+ if (q->testAttribute(Qt::WA_WState_Created))
+ hide_helper();
// invalidate layout similar to updateGeometry()
- if (!isWindow() && parentWidget()) {
- if (parentWidget()->d_func()->layout)
- parentWidget()->d_func()->layout->invalidate();
- else if (parentWidget()->isVisible())
- QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest));
+ if (!q->isWindow() && q->parentWidget()) {
+ if (q->parentWidget()->d_func()->layout)
+ q->parentWidget()->d_func()->layout->invalidate();
+ else if (q->parentWidget()->isVisible())
+ QApplication::postEvent(q->parentWidget(), new QEvent(QEvent::LayoutRequest));
}
QEvent hideToParentEvent(QEvent::HideToParent);
- QApplication::sendEvent(this, &hideToParentEvent);
+ QApplication::sendEvent(q, &hideToParentEvent);
}
}
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index e50d828775..797963b931 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -485,6 +485,7 @@ public:
void hide_sys();
void hide_helper();
void _q_showIfNotHidden();
+ void setVisible(bool);
void setEnabled_helper(bool);
static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0);
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 991a05fa02..e9b749d7c2 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -73,7 +73,7 @@ public:
{
Q_Q(QWidgetWindow);
if (QWidget *widget = q->widget())
- widget->setVisible(visible);
+ QWidgetPrivate::get(widget)->setVisible(visible);
else
QWindowPrivate::setVisible(visible);
}
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 7637877926..47c5267c73 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -3064,19 +3064,22 @@ bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event)
{
Q_D(QCalendarWidget);
if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) {
+ // We can get filtered press events that were intended for Qt Virtual Keyboard's
+ // input panel (QQuickView), so we have to make sure that the window is indeed a QWidget - no static_cast.
+ // In addition, as we have a event filter on the whole application we first make sure that the top level widget
+ // of both this and the watched widget are the same to decide if we should finish the year edition.
QWidget *tlw = window();
- QWidget *widget = static_cast<QWidget*>(watched);
- //as we have a event filter on the whole application we first make sure that the top level widget
- //of both this and the watched widget are the same to decide if we should finish the year edition.
- if (widget->window() == tlw) {
- QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos());
- QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size());
- if (!geom.contains(mousePos)) {
- event->accept();
- d->_q_yearEditingFinished();
- setFocus();
- return true;
- }
+ QWidget *widget = qobject_cast<QWidget *>(watched);
+ if (!widget || widget->window() != tlw)
+ return QWidget::eventFilter(watched, event);
+
+ QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos());
+ QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size());
+ if (!geom.contains(mousePos)) {
+ event->accept();
+ d->_q_yearEditingFinished();
+ setFocus();
+ return true;
}
}
return QWidget::eventFilter(watched, event);