Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwidgetwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "private/qwindow_p.h"
5#include "qwidgetwindow_p.h"
6#include "qlayout.h"
7
8#include "private/qwidget_p.h"
9#include "private/qapplication_p.h"
10#if QT_CONFIG(accessibility)
11#include <QtGui/qaccessible.h>
12#endif
13#include <private/qwidgetrepaintmanager_p.h>
14#include <qpa/qwindowsysteminterface_p.h>
15#include <qpa/qplatformtheme.h>
16#include <qpa/qplatformwindow.h>
17#include <private/qgesturemanager_p.h>
18#include <private/qhighdpiscaling_p.h>
19
21
22using namespace Qt::StringLiterals;
23
24Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets();
25
26Q_WIDGETS_EXPORT QWidget *qt_button_down = nullptr; // widget got last button-down
27
28// popup control
29QWidget *qt_popup_down = nullptr; // popup that contains the pressed widget
30bool qt_popup_down_closed = false; // qt_popup_down has been closed
31
33
35{
36 Q_DECLARE_PUBLIC(QWidgetWindow)
37public:
38 void setVisible(bool visible) override
39 {
40 Q_Q(QWidgetWindow);
41 qCDebug(lcWidgetShowHide) << "Setting visibility of" << q->widget()
42 << "to" << visible << "via QWidgetWindowPrivate";
43
44 if (QWidget *widget = q->widget()) {
45 // If the widget's visible state is already matching the new QWindow
46 // visible state we assume the widget has already synced up.
47 if (visible != widget->isVisible())
49 }
50
51 // If we end up calling QWidgetPrivate::setVisible() above, we will
52 // in most cases recurse back into setNativeWindowVisibility() to
53 // update the QWindow state. But during QWidget::destroy() this is
54 // not the case, as Qt::WA_WState_Created has been unset by the time
55 // we check if we should call hide_helper(). We handle this case, as
56 // well as the cases where we don't call QWidgetPrivate::setVisible(),
57 // by syncing up the QWindow state here if needed.
58 if (q->isVisible() != visible)
60 }
61
62 QWindow *eventReceiver() override {
63 Q_Q(QWidgetWindow);
64 QWindow *w = q;
65 while (w->parent() && qobject_cast<QWidgetWindow *>(w) && qobject_cast<QWidgetWindow *>(w->parent())) {
66 w = w->parent();
67 }
68 return w;
69 }
70
71 void clearFocusObject() override
72 {
73 Q_Q(QWidgetWindow);
74 QWidget *widget = q->widget();
75 if (widget && widget->focusWidget())
77 }
78
80 {
81 Q_Q(QWidgetWindow);
82 QWidget *widget = q->widget();
83 if (!widget)
84 return;
85 QWidget *newFocusWidget = nullptr;
86
87 switch (target) {
89 newFocusWidget = q->getFocusWidget(QWidgetWindow::FirstFocusWidget);
90 break;
92 newFocusWidget = q->getFocusWidget(QWidgetWindow::LastFocusWidget);
93 break;
94 case FocusTarget::Next: {
95 QWidget *focusWidget = widget->focusWidget() ? widget->focusWidget() : widget;
96 newFocusWidget = focusWidget->nextInFocusChain() ? focusWidget->nextInFocusChain() : focusWidget;
97 break;
98 }
99 case FocusTarget::Prev: {
100 QWidget *focusWidget = widget->focusWidget() ? widget->focusWidget() : widget;
101 newFocusWidget = focusWidget->previousInFocusChain() ? focusWidget->previousInFocusChain() : focusWidget;
102 break;
103 }
104 default:
105 break;
106 }
107
108 if (newFocusWidget)
109 newFocusWidget->setFocus(reason);
110 }
111
112 QRectF closestAcceptableGeometry(const QRectF &rect) const override;
113
115 {
116 Q_Q(QWidgetWindow);
117 if (QWidget *widget = q->widget())
118 QWidgetPrivate::get(widget)->updateContentsRect();
119 }
120
121 bool participatesInLastWindowClosed() const override;
122 bool treatAsVisible() const override;
123};
124
126{
127 Q_Q(const QWidgetWindow);
128 const QWidget *widget = q->widget();
129 if (!widget || !widget->isWindow() || !widget->hasHeightForWidth())
130 return QRect();
131 const QSize oldSize = rect.size().toSize();
132 const QSize newSize = QLayout::closestAcceptableSize(widget, oldSize);
133 if (newSize == oldSize)
134 return QRectF();
135 const int dw = newSize.width() - oldSize.width();
136 const int dh = newSize.height() - oldSize.height();
138 const QRectF currentGeometry(widget->geometry());
139 const qreal topOffset = result.top() - currentGeometry.top();
140 const qreal bottomOffset = result.bottom() - currentGeometry.bottom();
141 if (qAbs(topOffset) > qAbs(bottomOffset))
142 result.setTop(result.top() - dh); // top edge drag
143 else
144 result.setBottom(result.bottom() + dh); // bottom edge drag
145 const qreal leftOffset = result.left() - currentGeometry.left();
146 const qreal rightOffset = result.right() - currentGeometry.right();
148 result.setLeft(result.left() - dw); // left edge drag
149 else
150 result.setRight(result.right() + dw); // right edge drag
151 return result;
152}
153
155
158 , m_widget(widget)
159{
160 updateObjectName();
163 if (q_evaluateRhiConfig(m_widget, nullptr, &type))
164 setSurfaceType(type);
165 }
166
167 connect(widget, &QObject::objectNameChanged, this, &QWidgetWindow::updateObjectName);
168 connect(this, &QWidgetWindow::screenChanged, this, &QWidgetWindow::handleScreenChange);
169}
170
172{
173 if (!m_widget)
174 return;
175
176 QTLWExtra *topData = QWidgetPrivate::get(m_widget)->topData();
177 Q_ASSERT(topData);
178
179 // The QPlaformBackingStore may hold a reference to the window,
180 // so the backingstore needs to be deleted first.
181 topData->repaintManager.reset(nullptr);
182 delete topData->backingStore;
183 topData->backingStore = nullptr;
184 topData->widgetTextures.clear();
185
186 // Too late to do anything beyond this point
187 topData->window = nullptr;
188}
189
190#if QT_CONFIG(accessibility)
191QAccessibleInterface *QWidgetWindow::accessibleRoot() const
192{
193 if (m_widget)
194 return QAccessible::queryAccessibleInterface(m_widget);
195 return nullptr;
196}
197#endif
198
200{
201 QWidget *windowWidget = m_widget;
202 if (!windowWidget)
203 return nullptr;
204
205 // A window can't have a focus object if it's being destroyed.
206 if (QWidgetPrivate::get(windowWidget)->data.in_destructor)
207 return nullptr;
208
209 QWidget *widget = windowWidget->focusWidget();
210
211 if (!widget)
212 widget = windowWidget;
213
214 QObject *focusObj = QWidgetPrivate::get(widget)->focusObject();
215 if (focusObj)
216 return focusObj;
217
218 return widget;
219}
220
222{
223 Q_D(QWidgetWindow);
224 qCDebug(lcWidgetShowHide) << "Setting visibility of" << this
225 << "to" << visible << "via QWidgetWindow::setNativeWindowVisibility";
226
227 // Call base class setVisible() implementation to run the QWindow
228 // visibility logic. Don't call QWidgetWindowPrivate::setVisible()
229 // since that will recurse back into QWidget code.
230 d->QWindowPrivate::setVisible(visible);
231}
232
234{
235 switch (event->type()) {
236 // Handing show events to widgets would cause them to be triggered twice
237 case QEvent::Show:
238 case QEvent::Hide:
239 case QEvent::Timer:
243 case QEvent::Paint:
244 case QEvent::Close: // Propagated manually in closeEvent
245 return false;
246 default:
247 return true;
248 }
249}
250
252{
253 if (!m_widget)
254 return QWindow::event(event);
255
256 switch (event->type()) {
257 case QEvent::Enter:
258 case QEvent::Leave:
260 return true;
261
262 // these should not be sent to QWidget, the corresponding events
263 // are sent by QApplicationPrivate::notifyActiveWindowChange()
264 case QEvent::FocusIn:
265 handleFocusInEvent(static_cast<QFocusEvent *>(event));
267 case QEvent::FocusOut: {
268#if QT_CONFIG(accessibility)
270 state.active = true;
271 QAccessibleStateChangeEvent ev(m_widget, state);
272 QAccessible::updateAccessibility(&ev);
273#endif
274 return false; }
275
280
281 QGuiApplication::forwardEvent(QApplicationPrivate::focus_widget, event);
282 }
283 return true;
284
285 case QEvent::KeyPress:
288 handleKeyEvent(static_cast<QKeyEvent *>(event));
289 return true;
290
295 handleMouseEvent(static_cast<QMouseEvent *>(event));
296 return true;
297
303 return true;
304
307 case QEvent::TouchEnd:
309 handleTouchEvent(static_cast<QTouchEvent *>(event));
310 return true;
311
312 case QEvent::Move:
313 handleMoveEvent(static_cast<QMoveEvent *>(event));
314 return true;
315
316 case QEvent::Resize:
317 handleResizeEvent(static_cast<QResizeEvent *>(event));
318 return true;
319
320#if QT_CONFIG(wheelevent)
321 case QEvent::Wheel:
322 handleWheelEvent(static_cast<QWheelEvent *>(event));
323 return true;
324#endif
325
326#if QT_CONFIG(draganddrop)
328 handleDragEnterEvent(static_cast<QDragEnterEvent *>(event));
329 return true;
330 case QEvent::DragMove:
331 handleDragMoveEvent(static_cast<QDragMoveEvent *>(event));
332 return true;
334 handleDragLeaveEvent(static_cast<QDragLeaveEvent *>(event));
335 return true;
336 case QEvent::Drop:
337 handleDropEvent(static_cast<QDropEvent *>(event));
338 return true;
339#endif
340
341 case QEvent::Expose:
342 handleExposeEvent(static_cast<QExposeEvent *>(event));
343 return true;
344
346 QWindow::event(event); // Update QWindow::Visibility and emit signals.
348 return true;
349
350 case QEvent::ThemeChange: {
351 QEvent widgetEvent(QEvent::ThemeChange);
352 QCoreApplication::forwardEvent(m_widget, &widgetEvent, event);
353 }
354 return true;
355
356#if QT_CONFIG(tabletevent)
360 handleTabletEvent(static_cast<QTabletEvent *>(event));
361 return true;
362#endif
363
364#ifndef QT_NO_GESTURES
367 return true;
368#endif
369
370#ifndef QT_NO_CONTEXTMENU
373 return true;
374#endif // QT_NO_CONTEXTMENU
375
377 qt_button_down = nullptr;
378 break;
379
381 // This is not the same as an UpdateRequest for a QWidget. That just
382 // syncs the backing store while here we also must mark as dirty.
383 m_widget->repaint();
384 return true;
385
387 handleDevicePixelRatioChange();
388 break;
389
390 default:
391 break;
392 }
393
394 if (shouldBePropagatedToWidget(event) && QCoreApplication::forwardEvent(m_widget, event))
395 return true;
396
397 return QWindow::event(event);
398}
399
400QPointer<QWidget> qt_last_mouse_receiver = nullptr;
401
403{
404 // Ignore all enter/leave events from QPA if we are not on the first-level context menu.
405 // This prevents duplicated events on most platforms. Fake events will be delivered in
406 // QWidgetWindow::handleMouseEvent(QMouseEvent *). Make an exception whether the widget
407 // is already under mouse - let the mouse leave.
409 return;
410
411 if (event->type() == QEvent::Leave) {
412 QWidget *enter = nullptr;
413 // Check from window system event queue if the next queued enter targets a window
414 // in the same window hierarchy (e.g. enter a child of this window). If so,
415 // remove the enter event from queue and handle both in single dispatch.
419 const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QPointF(QGuiApplicationPrivate::lastCursorPosition);
420 if (systemEvent) {
421 if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter))
422 {
423 QWindow *thisParent = this;
424 QWindow *enterParent = enterWindow;
425 while (thisParent->parent())
426 thisParent = thisParent->parent();
427 while (enterParent->parent())
428 enterParent = enterParent->parent();
429 if (thisParent == enterParent) {
431 enter = enterWindow->widget();
433 }
434 }
435 }
436 // Enter-leave between sibling widgets is ignored when there is a mousegrabber - this makes
437 // both native and non-native widgets work similarly.
438 // When mousegrabbing, leaves are only generated if leaving the parent window.
439 if (!enter || !QWidget::mouseGrabber()) {
440 // Preferred leave target is the last mouse receiver, unless it has native window,
441 // in which case it is assumed to receive it's own leave event when relevant.
442 QWidget *leave = m_widget;
443 if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
447 }
448 } else {
449 const QEnterEvent *ee = static_cast<QEnterEvent *>(event);
450 QWidget *child = m_widget->childAt(ee->position().toPoint());
451 QWidget *receiver = child ? child : m_widget.data();
452 QWidget *leave = nullptr;
453 if (QApplicationPrivate::inPopupMode() && receiver == m_widget
454 && qt_last_mouse_receiver != m_widget) {
455 // This allows to deliver the leave event to the native widget
456 // action on first-level menu.
458 }
460 qt_last_mouse_receiver = receiver;
461 }
462}
463
464QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw)
465{
466 QWidget *tlw = m_widget;
467 QWidget *w = tlw->nextInFocusChain();
468
469 QWidget *last = tlw;
470
472
473 while (w != tlw)
474 {
475 if (((w->focusPolicy() & focus_flag) == focus_flag)
476 && w->isVisibleTo(m_widget) && w->isEnabled())
477 {
478 last = w;
479 if (fw == FirstFocusWidget)
480 break;
481 }
482 w = w->nextInFocusChain();
483 }
484
485 return last;
486}
487
489{
490 QWidget *focusWidget = nullptr;
491 if (e->reason() == Qt::BacktabFocusReason)
492 focusWidget = getFocusWidget(LastFocusWidget);
493 else if (e->reason() == Qt::TabFocusReason)
494 focusWidget = getFocusWidget(FirstFocusWidget);
495
496 if (focusWidget != nullptr)
497 focusWidget->setFocus();
498}
499
501{
502 QApplication::forwardEvent(m_widget, e);
503}
504
506{
508 QPointer<QWidget> activePopupWidget = QApplication::activePopupWidget();
509 QPointF mapped = event->position();
510 if (activePopupWidget != m_widget)
511 mapped = activePopupWidget->mapFromGlobal(event->globalPosition());
512 bool releaseAfter = false;
513 QWidget *popupChild = activePopupWidget->childAt(mapped.toPoint());
514
515 if (activePopupWidget != qt_popup_down) {
516 qt_button_down = nullptr;
517 qt_popup_down = nullptr;
518 }
519
520 switch (event->type()) {
523 qt_button_down = popupChild;
524 qt_popup_down = activePopupWidget;
525 qt_popup_down_closed = false;
526 break;
528 releaseAfter = true;
529 break;
530 default:
531 break; // nothing for mouse move
532 }
533
534 if (activePopupWidget->isEnabled()) {
535 // deliver event
536 QPointer<QWidget> receiver = activePopupWidget;
537 QPointF widgetPos = mapped;
538 if (qt_button_down)
539 receiver = qt_button_down;
540 else if (popupChild)
541 receiver = popupChild;
542 if (receiver != activePopupWidget)
543 widgetPos = receiver->mapFromGlobal(event->globalPosition());
544
545 const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped.toPoint());
546 const bool underMouse = activePopupWidget->underMouse();
547 if (underMouse != reallyUnderMouse) {
548 if (reallyUnderMouse) {
549 const QPoint receiverMapped = receiver->mapFromGlobal(event->globalPosition().toPoint());
550 // Prevent negative mouse position on enter event - this event
551 // should be properly handled in "handleEnterLeaveEvent()".
552 if (receiverMapped.x() >= 0 && receiverMapped.y() >= 0) {
553 QApplicationPrivate::dispatchEnterLeave(receiver, nullptr, event->globalPosition());
554 qt_last_mouse_receiver = receiver;
555 }
556 } else {
558 qt_last_mouse_receiver = receiver;
559 receiver = activePopupWidget;
560 }
561 }
562
563 if ((event->type() != QEvent::MouseButtonPress) || !(QMutableSinglePointEvent::from(event)->isDoubleClick())) {
564 // if the widget that was pressed is gone, then deliver move events without buttons
565 const auto buttons = event->type() == QEvent::MouseMove && qt_popup_down_closed
566 ? Qt::NoButton : event->buttons();
567 QMouseEvent e(event->type(), widgetPos, event->scenePosition(), event->globalPosition(),
568 event->button(), buttons, event->modifiers(),
569 event->source(), event->pointingDevice());
570 e.setTimestamp(event->timestamp());
571 QApplicationPrivate::sendMouseEvent(receiver, &e, receiver, receiver->window(), &qt_button_down, qt_last_mouse_receiver);
572 qt_last_mouse_receiver = receiver;
573 }
574 } else {
575 // close disabled popups when a mouse button is pressed or released
576 switch (event->type()) {
580 activePopupWidget->close();
581 break;
582 default:
583 break;
584 }
585 }
586
587 if (releaseAfter) {
588 qt_button_down = nullptr;
589 qt_popup_down_closed = false;
590 qt_popup_down = nullptr;
591 }
592 return;
593 }
594
595 qt_popup_down_closed = false;
596 // modal event handling
597 if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
598 return;
599
600 // which child should have it?
601 QWidget *widget = m_widget->childAt(event->position().toPoint());
602 QPoint mapped = event->position().toPoint();
603
604 if (!widget)
605 widget = m_widget;
606
607 const bool initialPress = event->buttons() == event->button();
608 if (event->type() == QEvent::MouseButtonPress && initialPress)
610
611 QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->scenePosition().toPoint(), &mapped, event->type(), event->buttons(),
613 if (!receiver)
614 return;
615
616 if (d_func()->isPopup() && receiver->window()->windowHandle() != this) {
617 receiver = widget;
618 mapped = event->position().toPoint();
619 }
620
621 if ((event->type() != QEvent::MouseButtonPress) || !QMutableSinglePointEvent::from(event)->isDoubleClick()) {
622
623 // The preceding statement excludes MouseButtonPress events which caused
624 // creation of a MouseButtonDblClick event. QTBUG-25831
625 QMouseEvent translated(event->type(), mapped, event->scenePosition(), event->globalPosition(),
626 event->button(), event->buttons(), event->modifiers(),
627 event->source(), event->pointingDevice());
628 translated.setTimestamp(event->timestamp());
629 QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget,
631 event->setAccepted(translated.isAccepted());
632 }
633#ifndef QT_NO_CONTEXTMENU
635 && event->button() == Qt::RightButton
636 && m_widget->rect().contains(event->position().toPoint())) {
637 QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPosition().toPoint(), event->modifiers());
638 QGuiApplication::forwardEvent(receiver, &e, event);
639 if (e.isAccepted())
640 event->accept();
641 }
642#endif
643}
644
646{
647 if (event->type() == QEvent::TouchCancel) {
648 QApplicationPrivate::translateTouchCancel(event->pointingDevice(), event->timestamp());
649 event->accept();
651 // Ignore touch events for popups. This will cause QGuiApplication to synthesise mouse
652 // events instead, which QWidgetWindow::handleMouseEvent will forward correctly:
653 event->ignore();
654 } else {
655 event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event));
656 }
657}
658
660{
661 if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
662 return;
663
664 QObject *receiver = QWidget::keyboardGrabber();
665 if (!receiver && QApplicationPrivate::inPopupMode()) {
667 QWidget *popupFocusWidget = popup->focusWidget();
668 receiver = popupFocusWidget ? popupFocusWidget : popup;
669 }
670 if (!receiver)
671 receiver = focusObject();
672 QGuiApplication::forwardEvent(receiver, event);
673}
674
675bool QWidgetWindow::updateSize()
676{
677 bool changed = false;
679 return changed;
681 return changed;
682
683 if (m_widget->data->crect.size() != geometry().size()) {
684 changed = true;
685 m_widget->data->crect.setSize(geometry().size());
686 }
687
688 updateMargins();
689 return changed;
690}
691
692void QWidgetWindow::updateMargins()
693{
694 // QTBUG-79147 (Windows): Bail out on resize events after closing a dialog
695 // and destroying the platform window which would clear the margins.
696 QTLWExtra *te = m_widget->d_func()->topData();
697 if (te->window == nullptr || te->window->handle() == nullptr)
698 return;
699 const QMargins margins = frameMargins();
700 te->posIncludesFrame= false;
701 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
702 m_widget->data->fstrut_dirty = false;
703}
704
706{
707 QEvent e(type);
710 for (int i = 0; i < d->children.size(); ++i) {
711 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
712 if (w)
714 }
715}
716
717void QWidgetWindow::handleScreenChange()
718{
719 // Send an event recursively to the widget and its children.
721
722 // Invalidate the backing store buffer and repaint immediately.
723 if (screen())
724 repaintWindow();
725}
726
727void QWidgetWindow::handleDevicePixelRatioChange()
728{
729 // Send an event recursively to the widget and its children.
731
732 // Invalidate the backing store buffer and repaint immediately.
733 if (screen())
734 repaintWindow();
735}
736
737void QWidgetWindow::repaintWindow()
738{
739 if (!m_widget->isVisible() || !m_widget->updatesEnabled() || !m_widget->rect().isValid())
740 return;
741
742 QTLWExtra *tlwExtra = m_widget->window()->d_func()->maybeTopData();
743 if (tlwExtra && tlwExtra->backingStore)
744 tlwExtra->repaintManager->markDirty(m_widget->rect(), m_widget,
746}
747
748// Store normal geometry used for saving application settings.
749void QWidgetWindow::updateNormalGeometry()
750{
751 QTLWExtra *tle = m_widget->d_func()->maybeTopData();
752 if (!tle)
753 return;
754 // Ask platform window, default to widget geometry.
755 QRect normalGeometry;
756 if (const QPlatformWindow *pw = handle())
757 normalGeometry = QHighDpi::fromNativePixels(pw->normalGeometry(), this);
758 if (!normalGeometry.isValid() && !(m_widget->windowState() & ~Qt::WindowActive))
759 normalGeometry = m_widget->geometry();
760 if (normalGeometry.isValid())
761 tle->normalGeometry = normalGeometry;
762}
763
765{
767 return;
769 return;
770
771 auto oldPosition = m_widget->data->crect.topLeft();
772 auto newPosition = geometry().topLeft();
773
774 if (!m_widget->isWindow()) {
775 if (auto *nativeParent = m_widget->nativeParentWidget())
776 newPosition = m_widget->parentWidget()->mapFrom(nativeParent, newPosition);
777 }
778
779 bool changed = newPosition != oldPosition;
780
781 if (changed)
782 m_widget->data->crect.moveTopLeft(newPosition);
783
784 updateMargins(); // FIXME: Only do when changed?
785
786 if (changed) {
787 QMoveEvent widgetEvent(newPosition, oldPosition);
788 QGuiApplication::forwardEvent(m_widget, &widgetEvent, event);
789 }
790}
791
793{
794 auto oldRect = m_widget->rect();
795
796 if (updateSize()) {
797 QGuiApplication::forwardEvent(m_widget, event);
798
799 if (m_widget->d_func()->shouldPaintOnScreen()) {
800 QRegion dirtyRegion = m_widget->rect();
802 dirtyRegion -= oldRect;
803 m_widget->d_func()->syncBackingStore(dirtyRegion);
804 } else {
805 m_widget->d_func()->syncBackingStore();
806 }
807 }
808}
809
811{
812 Q_D(QWidgetWindow);
813 if (qt_popup_down == m_widget) {
814 qt_popup_down = nullptr;
816 }
817 bool accepted = m_widget->d_func()->handleClose(d->inClose ? QWidgetPrivate::CloseWithEvent
819 event->setAccepted(accepted);
820}
821
823{
824 Q_Q(const QWidgetWindow);
825
826 // For historical reasons WA_QuitOnClose has been closely tied
827 // to the lastWindowClosed signal, since the default behavior
828 // is to quit the application after emitting lastWindowClosed.
829 // ### Qt 7: Rename this attribute, or decouple behavior.
830 if (!q->widget()->testAttribute(Qt::WA_QuitOnClose))
831 return false;
832
834}
835
837{
838 Q_Q(const QWidgetWindow);
839
840 // Widget windows may have Qt::WA_DontShowOnScreen, in which case the
841 // QQWidget will be visible, but the corresponding QWindow will not.
842 // Since the lastWindowClosed logic relies on checking whether the
843 // closed window was visible, and if there are any remaining visible
844 // windows, we need to reflect the QWidget state, not the QWindow one.
845 return q->widget()->isVisible();
846}
847
848#if QT_CONFIG(wheelevent)
849
850void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
851{
852 if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
853 return;
854
855 QWidget *rootWidget = m_widget;
856 QPointF pos = event->position();
857
858 // Use proper popup window for wheel event. Some QPA sends the wheel
859 // event to the root menu, so redirect it to the proper popup window.
860 QWidget *activePopupWidget = QApplication::activePopupWidget();
861 if (activePopupWidget && activePopupWidget != m_widget) {
862 rootWidget = activePopupWidget;
863 pos = rootWidget->mapFromGlobal(event->globalPosition());
864 }
865
866 // which child should have it?
867 QWidget *widget = rootWidget->childAt(pos.toPoint());
868
869 if (!widget)
870 widget = rootWidget;
871
872 QPointF mapped = widget->mapFrom(rootWidget, pos);
873
874 QWheelEvent translated(mapped, event->globalPosition(), event->pixelDelta(), event->angleDelta(),
875 event->buttons(), event->modifiers(), event->phase(), event->inverted(),
876 event->source(), event->pointingDevice());
877 translated.setTimestamp(event->timestamp());
878 QGuiApplication::forwardEvent(widget, &translated, event);
879}
880
881#endif // QT_CONFIG(wheelevent)
882
883#if QT_CONFIG(draganddrop)
884
885static QWidget *findDnDTarget(QWidget *parent, const QPoint &pos)
886{
887 // Find a target widget under mouse that accepts drops (QTBUG-22987).
888 QWidget *widget = parent->childAt(pos);
889 if (!widget)
890 widget = parent;
891 for ( ; widget && !widget->isWindow() && !widget->acceptDrops(); widget = widget->parentWidget()) ;
892 if (widget && !widget->acceptDrops())
893 widget = nullptr;
894 return widget;
895}
896
897void QWidgetWindow::handleDragEnterEvent(QDragEnterEvent *event, QWidget *widget)
898{
899 Q_ASSERT(m_dragTarget == nullptr);
900 if (!widget)
901 widget = findDnDTarget(m_widget, event->position().toPoint());
902 if (!widget) {
903 event->ignore();
904 return;
905 }
906 m_dragTarget = widget;
907
908 const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->position().toPoint()));
909 QDragEnterEvent translated(mapped, event->possibleActions(), event->mimeData(),
910 event->buttons(), event->modifiers());
911 QGuiApplication::forwardEvent(m_dragTarget, &translated, event);
912 event->setAccepted(translated.isAccepted());
913 event->setDropAction(translated.dropAction());
914}
915
916void QWidgetWindow::handleDragMoveEvent(QDragMoveEvent *event)
917{
918 QPointer<QWidget> widget = findDnDTarget(m_widget, event->position().toPoint());
919 if (!widget) {
920 event->ignore();
921 if (m_dragTarget) { // Send DragLeave to previous
922 QDragLeaveEvent leaveEvent;
923 QWidget *dragTarget = m_dragTarget;
924 m_dragTarget = nullptr;
925 QGuiApplication::forwardEvent(dragTarget, &leaveEvent, event);
926 }
927 } else {
928 const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->position().toPoint()));
929 QDragMoveEvent translated(mapped, event->possibleActions(), event->mimeData(),
930 event->buttons(), event->modifiers());
931
932 if (widget == m_dragTarget) { // Target widget unchanged: Send DragMove
933 translated.setDropAction(event->dropAction());
934 translated.setAccepted(event->isAccepted());
935 QGuiApplication::forwardEvent(m_dragTarget, &translated, event);
936 } else {
937 if (m_dragTarget) { // Send DragLeave to previous
938 QDragLeaveEvent leaveEvent;
939 QWidget *dragTarget = m_dragTarget;
940 m_dragTarget = nullptr;
941 QGuiApplication::forwardEvent(dragTarget, &leaveEvent, event);
942 }
943 // widget might have been deleted when handling the leaveEvent
944 if (widget) {
945 // Send DragEnter to new widget.
946 handleDragEnterEvent(static_cast<QDragEnterEvent*>(event), widget);
947 // Handling 'DragEnter' should suffice for the application.
948 translated.setDropAction(event->dropAction());
949 translated.setAccepted(event->isAccepted());
950 // The drag enter event is always immediately followed by a drag move event,
951 // see QDragEnterEvent documentation.
952 if (m_dragTarget)
953 QGuiApplication::forwardEvent(m_dragTarget, &translated, event);
954 }
955 }
956 event->setAccepted(translated.isAccepted());
957 event->setDropAction(translated.dropAction());
958 }
959}
960
961void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *event)
962{
963 if (m_dragTarget) {
964 QWidget *dragTarget = m_dragTarget;
965 m_dragTarget = nullptr;
966 QGuiApplication::forwardEvent(dragTarget, event);
967 }
968}
969
970void QWidgetWindow::handleDropEvent(QDropEvent *event)
971{
972 if (Q_UNLIKELY(m_dragTarget.isNull())) {
973 qWarning() << m_widget << ": No drag target set.";
974 event->ignore();
975 return;
976 }
977 const QPoint mapped = m_dragTarget->mapFromGlobal(m_widget->mapToGlobal(event->position().toPoint()));
978 QDropEvent translated(mapped, event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
979 QWidget *dragTarget = m_dragTarget;
980 m_dragTarget = nullptr;
981 QGuiApplication::forwardEvent(dragTarget, &translated, event);
982 event->setAccepted(translated.isAccepted());
983 event->setDropAction(translated.dropAction());
984}
985
986#endif // QT_CONFIG(draganddrop)
987
989{
991 return; // Ignore for widgets that fake exposure
992
993 QWidgetPrivate *wPriv = m_widget->d_func();
994 const bool exposed = isExposed();
995
996 if (wPriv->childrenHiddenByWState) {
997 // If widgets has been previously hidden by window state change event
998 // and they aren't yet shown...
999 if (exposed) {
1000 // If the window becomes exposed...
1001 if (!wPriv->childrenShownByExpose) {
1002 // ... and they haven't been shown by this function yet - show it.
1003 wPriv->showChildren(true);
1005 QCoreApplication::forwardEvent(m_widget, &showEvent, event);
1006 wPriv->childrenShownByExpose = true;
1007 }
1008 } else {
1009 // If the window becomes not exposed...
1010 if (wPriv->childrenShownByExpose) {
1011 // ... and child widgets was previously shown by the expose event - hide widgets again.
1012 // This is a workaround, because sometimes when window is minimized programmatically,
1013 // the QPA can notify that the window is exposed after changing window state to minimized
1014 // and then, the QPA can send next expose event with null exposed region (not exposed).
1015 wPriv->hideChildren(true);
1017 QCoreApplication::forwardEvent(m_widget, &hideEvent, event);
1018 wPriv->childrenShownByExpose = false;
1019 }
1020 }
1021 }
1022
1023 if (exposed) {
1024 // QTBUG-39220, QTBUG-58575: set all (potentially fully obscured parent widgets) mapped.
1025 m_widget->setAttribute(Qt::WA_Mapped);
1026 for (QWidget *p = m_widget->parentWidget(); p && !p->testAttribute(Qt::WA_Mapped); p = p->parentWidget())
1027 p->setAttribute(Qt::WA_Mapped);
1028 if (!event->m_region.isNull())
1029 wPriv->syncBackingStore(event->m_region);
1030 } else {
1031 m_widget->setAttribute(Qt::WA_Mapped, false);
1032 }
1033}
1034
1036{
1037 // QWindow does currently not know 'active'.
1038 Qt::WindowStates eventState = event->oldState();
1039 Qt::WindowStates widgetState = m_widget->windowState();
1040 Qt::WindowStates windowState = windowStates();
1041 if (widgetState & Qt::WindowActive)
1042 eventState |= Qt::WindowActive;
1043
1044 // Determine the new widget state, remember maximized/full screen
1045 // during minimized.
1046 if (windowState & Qt::WindowMinimized) {
1047 widgetState |= Qt::WindowMinimized;
1048 } else {
1049 widgetState = windowState | (widgetState & Qt::WindowActive);
1050 if (windowState) // Maximized or FullScreen
1051 updateNormalGeometry();
1052 }
1053
1054 // Sent event if the state changed (that is, it is not triggered by
1055 // QWidget::setWindowState(), which also sends an event to the widget).
1056 if (widgetState != Qt::WindowStates::Int(m_widget->data->window_state)) {
1057 m_widget->data->window_state = uint(widgetState);
1058 QWindowStateChangeEvent widgetEvent(eventState);
1059 QGuiApplication::forwardEvent(m_widget, &widgetEvent, event);
1060 }
1061}
1062
1064{
1065 return m_widget->nativeEvent(eventType, message, result);
1066}
1067
1068#if QT_CONFIG(tabletevent)
1069void QWidgetWindow::handleTabletEvent(QTabletEvent *event)
1070{
1071 static QPointer<QWidget> qt_tablet_target = nullptr;
1072
1073 QWidget *widget = qt_tablet_target;
1074
1075 if (!widget) {
1076 widget = m_widget->childAt(event->position().toPoint());
1077 if (!widget)
1078 widget = m_widget;
1079 if (event->type() == QEvent::TabletPress)
1080 qt_tablet_target = widget;
1081 }
1082
1083 if (widget) {
1084 QPointF delta = event->globalPosition() - event->globalPosition().toPoint();
1085 QPointF mapped = widget->mapFromGlobal(event->globalPosition().toPoint()) + delta;
1086 QTabletEvent ev(event->type(), event->pointingDevice(), mapped, event->globalPosition(),
1087 event->pressure(), event->xTilt(), event->yTilt(), event->tangentialPressure(),
1088 event->rotation(), event->z(), event->modifiers(), event->button(), event->buttons());
1089 ev.setTimestamp(event->timestamp());
1090 ev.setAccepted(false);
1091 QGuiApplication::forwardEvent(widget, &ev, event);
1092 event->setAccepted(ev.isAccepted());
1093 }
1094
1095 if (event->type() == QEvent::TabletRelease && event->buttons() == Qt::NoButton)
1096 qt_tablet_target = nullptr;
1097}
1098#endif // QT_CONFIG(tabletevent)
1099
1100#ifndef QT_NO_GESTURES
1102{
1103 // copy-pasted code to find correct widget follows:
1104 QObject *receiver = nullptr;
1107 QWidget *popupFocusWidget = popup->focusWidget();
1108 receiver = popupFocusWidget ? popupFocusWidget : popup;
1109 }
1110 if (!receiver)
1111 receiver = QApplication::widgetAt(e->globalPosition().toPoint());
1112 if (!receiver)
1113 receiver = m_widget; // last resort
1114
1115 QApplication::forwardEvent(receiver, e);
1116}
1117#endif // QT_NO_GESTURES
1118
1119#ifndef QT_NO_CONTEXTMENU
1121{
1122 // We are only interested in keyboard originating context menu events here,
1123 // mouse originated context menu events for widgets are generated in mouse handling methods.
1125 return;
1126
1128 if (!fw) {
1130 fw = (QApplication::activePopupWidget()->focusWidget()
1131 ? QApplication::activePopupWidget()->focusWidget()
1133 } else if (QApplication::focusWidget()) {
1135 } else {
1136 fw = m_widget;
1137 }
1138 }
1139 if (fw && fw->isEnabled()) {
1140 QPoint pos = fw->inputMethodQuery(Qt::ImCursorRectangle).toRect().center();
1142 e->modifiers());
1143 QGuiApplication::forwardEvent(fw, &widgetEvent, e);
1144 }
1145}
1146#endif // QT_NO_CONTEXTMENU
1147
1148void QWidgetWindow::updateObjectName()
1149{
1150 QString name = m_widget->objectName();
1151 if (name.isEmpty())
1152 name = QString::fromUtf8(m_widget->metaObject()->className()) + "Class"_L1;
1153 name += "Window"_L1;
1155}
1156
1158
1159#include "moc_qwidgetwindow_p.cpp"
\inmodule QtGui
static QWidget * pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos, QEvent::Type type, Qt::MouseButtons buttons, QWidget *buttonDown, QWidget *alienWidget)
static QApplicationPrivate * instance()
static QWidget * focus_widget
static bool inPopupMode()
static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF)
static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent)
static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget, QWidget *native, QWidget **buttonDown, QPointer< QWidget > &lastMouseReceiver, bool spontaneous=true, bool onlyDispatchEnterLeave=false)
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp)
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QWidget * activePopupWidget()
Returns the active popup widget.
\inmodule QtCore
Definition qbytearray.h:57
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
Reason reason() const
Returns the reason for this context event.
Definition qevent.h:614
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
\inmodule QtGui
Definition qevent.h:165
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ TabletMove
Definition qcoreevent.h:121
@ NonClientAreaMouseButtonDblClick
Definition qcoreevent.h:215
@ WindowStateChange
Definition qcoreevent.h:143
@ DevicePixelRatioChange
Definition qcoreevent.h:287
@ FocusAboutToChange
Definition qcoreevent.h:68
@ ScreenChangeInternal
Definition qcoreevent.h:276
@ WindowBlocked
Definition qcoreevent.h:141
@ ShortcutOverride
Definition qcoreevent.h:158
@ FocusOut
Definition qcoreevent.h:67
@ ChildRemoved
Definition qcoreevent.h:108
@ NativeGesture
Definition qcoreevent.h:246
@ DragEnter
Definition qcoreevent.h:101
@ KeyRelease
Definition qcoreevent.h:65
@ MouseMove
Definition qcoreevent.h:63
@ KeyPress
Definition qcoreevent.h:64
@ FocusIn
Definition qcoreevent.h:66
@ TouchCancel
Definition qcoreevent.h:264
@ ThemeChange
Definition qcoreevent.h:266
@ MouseButtonPress
Definition qcoreevent.h:60
@ TouchUpdate
Definition qcoreevent.h:242
@ TouchBegin
Definition qcoreevent.h:241
@ NonClientAreaMouseMove
Definition qcoreevent.h:212
@ NonClientAreaMouseButtonRelease
Definition qcoreevent.h:214
@ TabletRelease
Definition qcoreevent.h:127
@ DynamicPropertyChange
Definition qcoreevent.h:207
@ UpdateRequest
Definition qcoreevent.h:113
@ DragLeave
Definition qcoreevent.h:103
@ TabletPress
Definition qcoreevent.h:126
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ NonClientAreaMouseButtonPress
Definition qcoreevent.h:213
@ ContextMenu
Definition qcoreevent.h:119
@ MouseButtonRelease
Definition qcoreevent.h:61
@ ChildAdded
Definition qcoreevent.h:106
bool isAccepted() const
Definition qcoreevent.h:308
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition qevent.h:515
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
Qt::FocusReason reason() const
Returns the reason for this focus event.
Definition qevent.cpp:1569
static QEvent::Type contextMenuEventType()
static QWindow * currentMouseWindow
static struct QGuiApplicationPrivate::QLastCursorPosition lastCursorPosition
static QInputMethod * inputMethod()
returns the input method.
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition qevent.h:56
The QKeyEvent class describes a key event.
Definition qevent.h:424
static QSize closestAcceptableSize(const QWidget *w, const QSize &s)
Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is ...
Definition qlayout.cpp:1398
\inmodule QtCore
Definition qmargins.h:24
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:115
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:106
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:112
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:109
\inmodule QtGui
Definition qevent.h:196
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:502
static QMutableSinglePointEvent * from(QSinglePointEvent *e)
Definition qevent_p.h:57
The QNativeGestureEvent class contains parameters that describe a gesture event. \inmodule QtGui.
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QString objectName
the name of this object
Definition qobject.h:107
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
void objectNameChanged(const QString &objectName, QPrivateSignal)
This signal is emitted after the object's name has been changed.
The QPlatformWindow class provides an abstraction for top-level windows.
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
void setTimestamp(quint64 timestamp) override
Definition qevent.cpp:338
T * data() const noexcept
Definition qpointer.h:74
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:170
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:855
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
Definition qevent.h:123
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6028
SurfaceType
The SurfaceType enum describes what type of surface this is.
Definition qsurface.h:30
@ RasterSurface
Definition qsurface.h:31
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
static QWidgetPrivate * get(QWidget *w)
Definition qwidget_p.h:212
@ CloseWithSpontaneousEvent
Definition qwidget_p.h:340
void processSafeAreaMarginsChanged() override
void clearFocusObject() override
void setFocusToTarget(FocusTarget target, Qt::FocusReason reason) override
bool participatesInLastWindowClosed() const override
QWindow * eventReceiver() override
void setVisible(bool visible) override
QRectF closestAcceptableGeometry(const QRectF &rect) const override
bool treatAsVisible() const override
void setNativeWindowVisibility(bool visible)
QObject * focusObject() const override
Returns the QObject that will be the final receiver of events tied focus, such as key events.
void handleMoveEvent(QMoveEvent *)
QWidgetWindow(QWidget *widget)
void handleMouseEvent(QMouseEvent *)
void handleFocusInEvent(QFocusEvent *)
void handleResizeEvent(QResizeEvent *)
void handleEnterLeaveEvent(QEvent *)
void handleTouchEvent(QTouchEvent *)
void handleKeyEvent(QKeyEvent *)
void handleContextMenuEvent(QContextMenuEvent *)
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override
Override this to handle platform dependent events.
bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
void handleExposeEvent(QExposeEvent *)
void closeEvent(QCloseEvent *) override
Override this to handle close events (ev).
void handleNonClientAreaMouseEvent(QMouseEvent *)
void handleGestureEvent(QNativeGestureEvent *)
void handleWindowStateChangedEvent(QWindowStateChangeEvent *event)
QWidget * widget() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
QWidget * nativeParentWidget() const
Definition qwidget.cpp:4349
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4329
virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
This special event handler can be reimplemented in a subclass to receive native platform events ident...
virtual bool hasHeightForWidth() const
QWidget * nextInFocusChain() const
Returns the next widget in this widget's focus chain.
Definition qwidget.cpp:6875
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
void clearFocus()
Takes keyboard input focus from the widget.
Definition qwidget.cpp:6713
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system.
Definition qwidget.h:798
QWidget * previousInFocusChain() const
The previousInFocusChain function returns the previous widget in this widget's focus chain.
Definition qwidget.cpp:6889
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6858
bool updatesEnabled
whether updates are enabled
Definition qwidget.h:143
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9942
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
bool isEnabled() const
Definition qwidget.h:814
static QWidget * mouseGrabber()
Returns the widget that is currently grabbing the mouse input.
QWindow * windowHandle() const
If this is a native widget, return the associated QWindow.
Definition qwidget.cpp:2497
static QWidget * keyboardGrabber()
Returns the widget that is currently grabbing the keyboard input.
QPointF mapFrom(const QWidget *, const QPointF &) const
Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate...
Definition qwidget.cpp:4245
bool acceptDrops
whether drop events are enabled for this widget
Definition qwidget.h:150
bool underMouse() const
Returns true if the widget is under the mouse cursor; otherwise returns false.
Definition qwidget.h:859
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition qwidget.h:811
Qt::WindowStates windowState() const
Returns the current window state.
Definition qwidget.cpp:2904
bool isVisible() const
Definition qwidget.h:874
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
virtual void setVisible(bool visible)
Definition qwindow.cpp:346
virtual bool participatesInLastWindowClosed() const
Definition qwindow.cpp:2393
\inmodule QtGui
Definition qevent.h:899
static void removeWindowSystemEvent(WindowSystemEvent *event)
static WindowSystemEvent * peekWindowSystemEvent(EventType t)
\inmodule QtGui
Definition qwindow.h:63
virtual QAccessibleInterface * accessibleRoot() const
Returns the accessibility interface for the object that the window represents.
Definition qwindow.cpp:2232
bool visible
whether the window is visible or not
Definition qwindow.h:90
QSize size() const override
Returns the size of the window excluding any window frame.
Definition qwindow.h:210
virtual bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
Definition qwindow.cpp:2572
virtual void hideEvent(QHideEvent *)
Override this to handle hide events (ev).
Definition qwindow.cpp:2547
void screenChanged(QScreen *screen)
This signal is emitted when a window's screen changes, either by being set explicitly with setScreen(...
virtual void showEvent(QShowEvent *)
Override this to handle show events (ev).
Definition qwindow.cpp:2536
QOpenGLWidget * widget
[1]
rect
[4]
else opt state
[0]
T fromNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
QFuture< QtPrivate::MapResultType< Sequence, MapFunctor > > mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
@ WindowMinimized
Definition qnamespace.h:253
@ WindowActive
Definition qnamespace.h:256
@ ImCursorRectangle
@ RightButton
Definition qnamespace.h:59
@ NoButton
Definition qnamespace.h:57
@ WA_QuitOnClose
Definition qnamespace.h:342
@ WA_DontShowOnScreen
Definition qnamespace.h:383
@ WA_OutsideWSRange
Definition qnamespace.h:315
@ WA_StaticContents
Definition qnamespace.h:288
@ WA_InputMethodEnabled
Definition qnamespace.h:295
@ WA_Mapped
Definition qnamespace.h:293
@ TabFocus
Definition qnamespace.h:108
@ StrongFocus
Definition qnamespace.h:110
@ AA_ForceRasterWidgets
Definition qnamespace.h:443
FocusReason
@ BacktabFocusReason
@ TabFocusReason
Q_WIDGETS_EXPORT QWidget * qt_button_down
bool qt_try_modal(QWidget *widget, QEvent::Type type)
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
Q_WIDGETS_EXPORT bool qt_tab_all_widgets()
static const double leftOffset
static const double rightOffset
#define qWarning
Definition qlogging.h:167
#define qCDebug(category,...)
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLenum target
GLuint GLsizei const GLchar * message
GLuint name
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QScreen * screen
[1]
Definition main.cpp:29
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
ptrdiff_t qintptr
Definition qtypes.h:166
#define leave(x)
bool q_evaluateRhiConfig(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1132
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786
static void sendChangeRecursively(QWidget *widget, QEvent::Type type)
bool qt_popup_down_closed
Q_WIDGETS_EXPORT bool qt_tab_all_widgets()
QWidget * qt_popup_down
bool q_evaluateRhiConfig(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1132
Q_WIDGETS_EXPORT QWidget * qt_button_down
static bool shouldBePropagatedToWidget(QEvent *event)
QPointer< QWidget > qt_last_mouse_receiver
bool qt_try_modal(QWidget *widget, QEvent::Type type)
QPointer< QWindow > qt_last_mouse_receiver
QObject::connect nullptr
QPoint oldPosition
[6]
QLayoutItem * child
[0]
std::unique_ptr< QWidgetRepaintManager > repaintManager
Definition qwidget_p.h:94
std::vector< std::unique_ptr< QPlatformTextureList > > widgetTextures
Definition qwidget_p.h:114
QBackingStore * backingStore
Definition qwidget_p.h:95
QWidgetWindow * window
Definition qwidget_p.h:97