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
30extern int openPopupCount;
31bool qt_popup_down_closed = false; // qt_popup_down has been closed
34
36{
37 Q_DECLARE_PUBLIC(QWidgetWindow)
38public:
39 void setVisible(bool visible) override
40 {
41 Q_Q(QWidgetWindow);
42 qCDebug(lcWidgetShowHide) << "Setting visibility of" << q->widget()
43 << "to" << visible << "via QWidgetWindowPrivate";
44
45 if (QWidget *widget = q->widget()) {
46 // If the widget's visible state is already matching the new QWindow
47 // visible state we assume the widget has already synced up.
48 if (visible != widget->isVisible())
50 }
51
52 // If we end up calling QWidgetPrivate::setVisible() above, we will
53 // in most cases recurse back into setNativeWindowVisibility() to
54 // update the QWindow state. But during QWidget::destroy() this is
55 // not the case, as Qt::WA_WState_Created has been unset by the time
56 // we check if we should call hide_helper(). We handle this case, as
57 // well as the cases where we don't call QWidgetPrivate::setVisible(),
58 // by syncing up the QWindow state here if needed.
59 if (q->isVisible() != visible)
61 }
62
63 QWindow *eventReceiver() override {
64 Q_Q(QWidgetWindow);
65 QWindow *w = q;
66 while (w->parent() && qobject_cast<QWidgetWindow *>(w) && qobject_cast<QWidgetWindow *>(w->parent())) {
67 w = w->parent();
68 }
69 return w;
70 }
71
72 void clearFocusObject() override
73 {
74 Q_Q(QWidgetWindow);
75 QWidget *widget = q->widget();
76 if (widget && widget->focusWidget())
78 }
79
81 {
82 Q_Q(QWidgetWindow);
83 QWidget *widget = q->widget();
84 if (!widget)
85 return;
86 QWidget *newFocusWidget = nullptr;
87
88 switch (target) {
90 newFocusWidget = q->getFocusWidget(QWidgetWindow::FirstFocusWidget);
91 break;
93 newFocusWidget = q->getFocusWidget(QWidgetWindow::LastFocusWidget);
94 break;
95 case FocusTarget::Next: {
96 QWidget *focusWidget = widget->focusWidget() ? widget->focusWidget() : widget;
97 newFocusWidget = focusWidget->nextInFocusChain() ? focusWidget->nextInFocusChain() : focusWidget;
98 break;
99 }
100 case FocusTarget::Prev: {
101 QWidget *focusWidget = widget->focusWidget() ? widget->focusWidget() : widget;
102 newFocusWidget = focusWidget->previousInFocusChain() ? focusWidget->previousInFocusChain() : focusWidget;
103 break;
104 }
105 default:
106 break;
107 }
108
109 if (newFocusWidget)
110 newFocusWidget->setFocus(reason);
111 }
112
113 QRectF closestAcceptableGeometry(const QRectF &rect) const override;
114
116 {
117 Q_Q(QWidgetWindow);
118 if (QWidget *widget = q->widget())
119 QWidgetPrivate::get(widget)->updateContentsRect();
120 }
121
122 bool participatesInLastWindowClosed() const override;
123 bool treatAsVisible() const override;
124};
125
127{
128 Q_Q(const QWidgetWindow);
129 const QWidget *widget = q->widget();
130 if (!widget || !widget->isWindow() || !widget->hasHeightForWidth())
131 return QRect();
132 const QSize oldSize = rect.size().toSize();
133 const QSize newSize = QLayout::closestAcceptableSize(widget, oldSize);
134 if (newSize == oldSize)
135 return QRectF();
136 const int dw = newSize.width() - oldSize.width();
137 const int dh = newSize.height() - oldSize.height();
139 const QRectF currentGeometry(widget->geometry());
140 const qreal topOffset = result.top() - currentGeometry.top();
141 const qreal bottomOffset = result.bottom() - currentGeometry.bottom();
142 if (qAbs(topOffset) > qAbs(bottomOffset))
143 result.setTop(result.top() - dh); // top edge drag
144 else
145 result.setBottom(result.bottom() + dh); // bottom edge drag
146 const qreal leftOffset = result.left() - currentGeometry.left();
147 const qreal rightOffset = result.right() - currentGeometry.right();
149 result.setLeft(result.left() - dw); // left edge drag
150 else
151 result.setRight(result.right() + dw); // right edge drag
152 return result;
153}
154
156
159 , m_widget(widget)
160{
161 updateObjectName();
164 q_evaluateRhiConfig(m_widget, nullptr, &type);
165 setSurfaceType(type);
166 }
167
168 connect(widget, &QObject::objectNameChanged, this, &QWidgetWindow::updateObjectName);
169 connect(this, &QWidgetWindow::screenChanged, this, &QWidgetWindow::handleScreenChange);
170}
171
173{
174 if (!m_widget)
175 return;
176
177 QTLWExtra *topData = QWidgetPrivate::get(m_widget)->topData();
178 Q_ASSERT(topData);
179
180 // The QPlaformBackingStore may hold a reference to the window,
181 // so the backingstore needs to be deleted first.
182 topData->repaintManager.reset(nullptr);
183 delete topData->backingStore;
184 topData->backingStore = nullptr;
185 topData->widgetTextures.clear();
186
187 // Too late to do anything beyond this point
188 topData->window = nullptr;
189}
190
191#if QT_CONFIG(accessibility)
192QAccessibleInterface *QWidgetWindow::accessibleRoot() const
193{
194 if (m_widget)
195 return QAccessible::queryAccessibleInterface(m_widget);
196 return nullptr;
197}
198#endif
199
201{
202 QWidget *windowWidget = m_widget;
203 if (!windowWidget)
204 return nullptr;
205
206 // A window can't have a focus object if it's being destroyed.
207 if (QWidgetPrivate::get(windowWidget)->data.in_destructor)
208 return nullptr;
209
210 QWidget *widget = windowWidget->focusWidget();
211
212 if (!widget)
213 widget = windowWidget;
214
215 QObject *focusObj = QWidgetPrivate::get(widget)->focusObject();
216 if (focusObj)
217 return focusObj;
218
219 return widget;
220}
221
223{
224 Q_D(QWidgetWindow);
225 qCDebug(lcWidgetShowHide) << "Setting visibility of" << this
226 << "to" << visible << "via QWidgetWindow::setNativeWindowVisibility";
227
228 // Call base class setVisible() implementation to run the QWindow
229 // visibility logic. Don't call QWidgetWindowPrivate::setVisible()
230 // since that will recurse back into QWidget code.
231 d->QWindowPrivate::setVisible(visible);
232}
233
235{
236 switch (event->type()) {
237 // Handing show events to widgets would cause them to be triggered twice
238 case QEvent::Show:
239 case QEvent::Hide:
240 case QEvent::Timer:
244 case QEvent::Paint:
245 case QEvent::Close: // Propagated manually in closeEvent
246 return false;
247 default:
248 return true;
249 }
250}
251
253{
254 if (!m_widget)
255 return QWindow::event(event);
256
257 switch (event->type()) {
258 case QEvent::Enter:
259 case QEvent::Leave:
261 return true;
262
263 // these should not be sent to QWidget, the corresponding events
264 // are sent by QApplicationPrivate::notifyActiveWindowChange()
265 case QEvent::FocusIn:
266 handleFocusInEvent(static_cast<QFocusEvent *>(event));
268 case QEvent::FocusOut: {
269#if QT_CONFIG(accessibility)
271 state.active = true;
272 QAccessibleStateChangeEvent ev(m_widget, state);
273 QAccessible::updateAccessibility(&ev);
274#endif
275 return false; }
276
281
282 QGuiApplication::forwardEvent(QApplicationPrivate::focus_widget, event);
283 }
284 return true;
285
286 case QEvent::KeyPress:
289 handleKeyEvent(static_cast<QKeyEvent *>(event));
290 return true;
291
296 handleMouseEvent(static_cast<QMouseEvent *>(event));
297 return true;
298
304 return true;
305
308 case QEvent::TouchEnd:
310 handleTouchEvent(static_cast<QTouchEvent *>(event));
311 return true;
312
313 case QEvent::Move:
314 handleMoveEvent(static_cast<QMoveEvent *>(event));
315 return true;
316
317 case QEvent::Resize:
318 handleResizeEvent(static_cast<QResizeEvent *>(event));
319 return true;
320
321#if QT_CONFIG(wheelevent)
322 case QEvent::Wheel:
323 handleWheelEvent(static_cast<QWheelEvent *>(event));
324 return true;
325#endif
326
327#if QT_CONFIG(draganddrop)
329 handleDragEnterEvent(static_cast<QDragEnterEvent *>(event));
330 return true;
331 case QEvent::DragMove:
332 handleDragMoveEvent(static_cast<QDragMoveEvent *>(event));
333 return true;
335 handleDragLeaveEvent(static_cast<QDragLeaveEvent *>(event));
336 return true;
337 case QEvent::Drop:
338 handleDropEvent(static_cast<QDropEvent *>(event));
339 return true;
340#endif
341
342 case QEvent::Expose:
343 handleExposeEvent(static_cast<QExposeEvent *>(event));
344 return true;
345
347 QWindow::event(event); // Update QWindow::Visibility and emit signals.
349 return true;
350
351 case QEvent::ThemeChange: {
352 QEvent widgetEvent(QEvent::ThemeChange);
353 QCoreApplication::forwardEvent(m_widget, &widgetEvent, event);
354 }
355 return true;
356
357#if QT_CONFIG(tabletevent)
361 handleTabletEvent(static_cast<QTabletEvent *>(event));
362 return true;
363#endif
364
365#ifndef QT_NO_GESTURES
368 return true;
369#endif
370
371#ifndef QT_NO_CONTEXTMENU
374 return true;
375#endif // QT_NO_CONTEXTMENU
376
378 qt_button_down = nullptr;
379 break;
380
382 // This is not the same as an UpdateRequest for a QWidget. That just
383 // syncs the backing store while here we also must mark as dirty.
384 m_widget->repaint();
385 return true;
386
388 handleDevicePixelRatioChange();
389 break;
390
391 default:
392 break;
393 }
394
395 if (shouldBePropagatedToWidget(event) && QCoreApplication::forwardEvent(m_widget, event))
396 return true;
397
398 return QWindow::event(event);
399}
400
401QPointer<QWidget> qt_last_mouse_receiver = nullptr;
402
404{
405 // Ignore all enter/leave events from QPA if we are not on the first-level context menu.
406 // This prevents duplicated events on most platforms. Fake events will be delivered in
407 // QWidgetWindow::handleMouseEvent(QMouseEvent *). Make an exception whether the widget
408 // is already under mouse - let the mouse leave.
410 return;
411
412 if (event->type() == QEvent::Leave) {
413 QWidget *enter = nullptr;
414 // Check from window system event queue if the next queued enter targets a window
415 // in the same window hierarchy (e.g. enter a child of this window). If so,
416 // remove the enter event from queue and handle both in single dispatch.
420 const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QPointF(QGuiApplicationPrivate::lastCursorPosition);
421 if (systemEvent) {
422 if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter))
423 {
424 QWindow *thisParent = this;
425 QWindow *enterParent = enterWindow;
426 while (thisParent->parent())
427 thisParent = thisParent->parent();
428 while (enterParent->parent())
429 enterParent = enterParent->parent();
430 if (thisParent == enterParent) {
432 enter = enterWindow->widget();
434 }
435 }
436 }
437 // Enter-leave between sibling widgets is ignored when there is a mousegrabber - this makes
438 // both native and non-native widgets work similarly.
439 // When mousegrabbing, leaves are only generated if leaving the parent window.
440 if (!enter || !QWidget::mouseGrabber()) {
441 // Preferred leave target is the last mouse receiver, unless it has native window,
442 // in which case it is assumed to receive it's own leave event when relevant.
443 QWidget *leave = m_widget;
444 if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
448 }
449 } else {
450 const QEnterEvent *ee = static_cast<QEnterEvent *>(event);
451 QWidget *child = m_widget->childAt(ee->position().toPoint());
452 QWidget *receiver = child ? child : m_widget.data();
453 QWidget *leave = nullptr;
454 if (QApplicationPrivate::inPopupMode() && receiver == m_widget
455 && qt_last_mouse_receiver != m_widget) {
456 // This allows to deliver the leave event to the native widget
457 // action on first-level menu.
459 }
461 qt_last_mouse_receiver = receiver;
462 }
463}
464
465QWidget *QWidgetWindow::getFocusWidget(FocusWidgets fw)
466{
467 QWidget *tlw = m_widget;
468 QWidget *w = tlw->nextInFocusChain();
469
470 QWidget *last = tlw;
471
473
474 while (w != tlw)
475 {
476 if (((w->focusPolicy() & focus_flag) == focus_flag)
477 && w->isVisibleTo(m_widget) && w->isEnabled())
478 {
479 last = w;
480 if (fw == FirstFocusWidget)
481 break;
482 }
483 w = w->nextInFocusChain();
484 }
485
486 return last;
487}
488
490{
491 QWidget *focusWidget = nullptr;
492 if (e->reason() == Qt::BacktabFocusReason)
493 focusWidget = getFocusWidget(LastFocusWidget);
494 else if (e->reason() == Qt::TabFocusReason)
495 focusWidget = getFocusWidget(FirstFocusWidget);
496
497 if (focusWidget != nullptr)
498 focusWidget->setFocus();
499}
500
502{
503 QApplication::forwardEvent(m_widget, e);
504}
505
507{
509 QPointer<QWidget> activePopupWidget = QApplication::activePopupWidget();
510 QPointF mapped = event->position();
511 if (activePopupWidget != m_widget)
512 mapped = activePopupWidget->mapFromGlobal(event->globalPosition());
513 bool releaseAfter = false;
514 QWidget *popupChild = activePopupWidget->childAt(mapped.toPoint());
515
516 if (activePopupWidget != qt_popup_down) {
517 qt_button_down = nullptr;
518 qt_popup_down = nullptr;
519 }
520
521 switch (event->type()) {
524 qt_button_down = popupChild;
525 qt_popup_down = activePopupWidget;
526 qt_popup_down_closed = false;
527 break;
529 releaseAfter = true;
530 break;
531 default:
532 break; // nothing for mouse move
533 }
534
535 int oldOpenPopupCount = openPopupCount;
536
537 if (activePopupWidget->isEnabled()) {
538 // deliver event
540 QPointer<QWidget> receiver = activePopupWidget;
541 QPointF widgetPos = mapped;
542 if (qt_button_down)
543 receiver = qt_button_down;
544 else if (popupChild)
545 receiver = popupChild;
546 if (receiver != activePopupWidget)
547 widgetPos = receiver->mapFromGlobal(event->globalPosition());
548
549 const bool reallyUnderMouse = activePopupWidget->rect().contains(mapped.toPoint());
550 const bool underMouse = activePopupWidget->underMouse();
551 if (underMouse != reallyUnderMouse) {
552 if (reallyUnderMouse) {
553 const QPoint receiverMapped = receiver->mapFromGlobal(event->globalPosition().toPoint());
554 // Prevent negative mouse position on enter event - this event
555 // should be properly handled in "handleEnterLeaveEvent()".
556 if (receiverMapped.x() >= 0 && receiverMapped.y() >= 0) {
557 QApplicationPrivate::dispatchEnterLeave(receiver, nullptr, event->globalPosition());
558 qt_last_mouse_receiver = receiver;
559 }
560 } else {
562 qt_last_mouse_receiver = receiver;
563 receiver = activePopupWidget;
564 }
565 }
566
567 if ((event->type() != QEvent::MouseButtonPress) || !(QMutableSinglePointEvent::from(event)->isDoubleClick())) {
568 // if the widget that was pressed is gone, then deliver move events without buttons
569 const auto buttons = event->type() == QEvent::MouseMove && qt_popup_down_closed
570 ? Qt::NoButton : event->buttons();
571 QMouseEvent e(event->type(), widgetPos, event->scenePosition(), event->globalPosition(),
572 event->button(), buttons, event->modifiers(),
573 event->source(), event->pointingDevice());
574 e.setTimestamp(event->timestamp());
575 QApplicationPrivate::sendMouseEvent(receiver, &e, receiver, receiver->window(), &qt_button_down, qt_last_mouse_receiver);
576 qt_last_mouse_receiver = receiver;
577 }
578 } else {
579 // close disabled popups when a mouse button is pressed or released
580 switch (event->type()) {
584 activePopupWidget->close();
585 break;
586 default:
587 break;
588 }
589 }
590
591 if (QApplication::activePopupWidget() != activePopupWidget
594 if (m_widget->windowType() != Qt::Popup)
595 qt_button_down = nullptr;
596 if (event->type() == QEvent::MouseButtonPress) {
597 // the popup disappeared, replay the mouse press event
598 QWidget *w = QApplication::widgetAt(event->globalPosition().toPoint());
600 // activate window of the widget under mouse pointer
601 if (!w->isActiveWindow()) {
602 w->activateWindow();
603 w->window()->raise();
604 }
605
607 const QRect globalGeometry = win->isTopLevel()
608 ? win->geometry()
609 : QRect(win->mapToGlobal(QPoint(0, 0)), win->size());
610 if (globalGeometry.contains(event->globalPosition().toPoint())) {
611 // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec()
612 const QPoint localPos = win->mapFromGlobal(event->globalPosition().toPoint());
613 QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPosition().toPoint(),
614 event->button(), event->buttons(), event->modifiers(), event->source());
616 e->setTimestamp(event->timestamp());
618 }
619 }
620 }
621 }
623#ifndef QT_NO_CONTEXTMENU
625 && event->button() == Qt::RightButton
626 && (openPopupCount == oldOpenPopupCount)) {
627 QWidget *receiver = activePopupWidget;
628 if (qt_button_down)
629 receiver = qt_button_down;
630 else if (popupChild)
631 receiver = popupChild;
632 const QPoint localPos = receiver->mapFromGlobal(event->globalPosition().toPoint());
633 QContextMenuEvent e(QContextMenuEvent::Mouse, localPos, event->globalPosition().toPoint(), event->modifiers());
634 QApplication::forwardEvent(receiver, &e, event);
635 }
636#else
637 Q_UNUSED(oldOpenPopupCount);
638 }
639#endif
640
641 if (releaseAfter) {
642 qt_button_down = nullptr;
643 qt_popup_down_closed = false;
644 qt_popup_down = nullptr;
645 }
646 return;
647 }
648
649 qt_popup_down_closed = false;
650 // modal event handling
651 if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
652 return;
653
654 // which child should have it?
655 QWidget *widget = m_widget->childAt(event->position().toPoint());
656 QPoint mapped = event->position().toPoint();
657
658 if (!widget)
659 widget = m_widget;
660
661 const bool initialPress = event->buttons() == event->button();
662 if (event->type() == QEvent::MouseButtonPress && initialPress)
664
665 QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->scenePosition().toPoint(), &mapped, event->type(), event->buttons(),
667 if (!receiver)
668 return;
669
670 if ((event->type() != QEvent::MouseButtonPress) || !QMutableSinglePointEvent::from(event)->isDoubleClick()) {
671
672 // The preceding statement excludes MouseButtonPress events which caused
673 // creation of a MouseButtonDblClick event. QTBUG-25831
674 QMouseEvent translated(event->type(), mapped, event->scenePosition(), event->globalPosition(),
675 event->button(), event->buttons(), event->modifiers(),
676 event->source(), event->pointingDevice());
677 translated.setTimestamp(event->timestamp());
678 QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget,
680 event->setAccepted(translated.isAccepted());
681 }
682#ifndef QT_NO_CONTEXTMENU
684 && event->button() == Qt::RightButton
685 && m_widget->rect().contains(event->position().toPoint())) {
686 QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPosition().toPoint(), event->modifiers());
687 QGuiApplication::forwardEvent(receiver, &e, event);
688 if (e.isAccepted())
689 event->accept();
690 }
691#endif
692}
693
695{
696 if (event->type() == QEvent::TouchCancel) {
697 QApplicationPrivate::translateTouchCancel(event->pointingDevice(), event->timestamp());
698 event->accept();
700 // Ignore touch events for popups. This will cause QGuiApplication to synthesise mouse
701 // events instead, which QWidgetWindow::handleMouseEvent will forward correctly:
702 event->ignore();
703 } else {
704 event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event));
705 }
706}
707
709{
710 if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
711 return;
712
713 QObject *receiver = QWidget::keyboardGrabber();
714 if (!receiver && QApplicationPrivate::inPopupMode()) {
716 QWidget *popupFocusWidget = popup->focusWidget();
717 receiver = popupFocusWidget ? popupFocusWidget : popup;
718 }
719 if (!receiver)
720 receiver = focusObject();
721 QGuiApplication::forwardEvent(receiver, event);
722}
723
724bool QWidgetWindow::updateSize()
725{
726 bool changed = false;
728 return changed;
730 return changed;
731
732 if (m_widget->data->crect.size() != geometry().size()) {
733 changed = true;
734 m_widget->data->crect.setSize(geometry().size());
735 }
736
737 updateMargins();
738 return changed;
739}
740
741void QWidgetWindow::updateMargins()
742{
743 // QTBUG-79147 (Windows): Bail out on resize events after closing a dialog
744 // and destroying the platform window which would clear the margins.
745 QTLWExtra *te = m_widget->d_func()->topData();
746 if (te->window == nullptr || te->window->handle() == nullptr)
747 return;
748 const QMargins margins = frameMargins();
749 te->posIncludesFrame= false;
750 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
751 m_widget->data->fstrut_dirty = false;
752}
753
755{
756 QEvent e(type);
759 for (int i = 0; i < d->children.size(); ++i) {
760 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
761 if (w)
763 }
764}
765
766void QWidgetWindow::handleScreenChange()
767{
768 // Send an event recursively to the widget and its children.
770
771 // Invalidate the backing store buffer and repaint immediately.
772 if (screen())
773 repaintWindow();
774}
775
776void QWidgetWindow::handleDevicePixelRatioChange()
777{
778 // Send an event recursively to the widget and its children.
780
781 // Invalidate the backing store buffer and repaint immediately.
782 if (screen())
783 repaintWindow();
784}
785
786void QWidgetWindow::repaintWindow()
787{
788 if (!m_widget->isVisible() || !m_widget->updatesEnabled() || !m_widget->rect().isValid())
789 return;
790
791 QTLWExtra *tlwExtra = m_widget->window()->d_func()->maybeTopData();
792 if (tlwExtra && tlwExtra->backingStore)
793 tlwExtra->repaintManager->markDirty(m_widget->rect(), m_widget,
795}
796
797// Store normal geometry used for saving application settings.
798void QWidgetWindow::updateNormalGeometry()
799{
800 QTLWExtra *tle = m_widget->d_func()->maybeTopData();
801 if (!tle)
802 return;
803 // Ask platform window, default to widget geometry.
804 QRect normalGeometry;
805 if (const QPlatformWindow *pw = handle())
806 normalGeometry = QHighDpi::fromNativePixels(pw->normalGeometry(), this);
807 if (!normalGeometry.isValid() && !(m_widget->windowState() & ~Qt::WindowActive))
808 normalGeometry = m_widget->geometry();
809 if (normalGeometry.isValid())
810 tle->normalGeometry = normalGeometry;
811}
812
814{
816 return;
818 return;
819
820 auto oldPosition = m_widget->data->crect.topLeft();
821 auto newPosition = geometry().topLeft();
822
823 if (!m_widget->isWindow()) {
824 if (auto *nativeParent = m_widget->nativeParentWidget())
825 newPosition = m_widget->parentWidget()->mapFrom(nativeParent, newPosition);
826 }
827
828 bool changed = newPosition != oldPosition;
829
830 if (changed)
831 m_widget->data->crect.moveTopLeft(newPosition);
832
833 updateMargins(); // FIXME: Only do when changed?
834
835 if (changed) {
836 QMoveEvent widgetEvent(newPosition, oldPosition);
837 QGuiApplication::forwardEvent(m_widget, &widgetEvent, event);
838 }
839}
840
842{
843 auto oldRect = m_widget->rect();
844
845 if (updateSize()) {
846 QGuiApplication::forwardEvent(m_widget, event);
847
848 if (m_widget->d_func()->shouldPaintOnScreen()) {
849 QRegion dirtyRegion = m_widget->rect();
851 dirtyRegion -= oldRect;
852 m_widget->d_func()->syncBackingStore(dirtyRegion);
853 } else {
854 m_widget->d_func()->syncBackingStore();
855 }
856 }
857}
858
860{
861 Q_D(QWidgetWindow);
862 bool accepted = m_widget->d_func()->handleClose(d->inClose ? QWidgetPrivate::CloseWithEvent
864 event->setAccepted(accepted);
865}
866
868{
869 Q_Q(const QWidgetWindow);
870
871 // For historical reasons WA_QuitOnClose has been closely tied
872 // to the lastWindowClosed signal, since the default behavior
873 // is to quit the application after emitting lastWindowClosed.
874 // ### Qt 7: Rename this attribute, or decouple behavior.
875 if (!q->widget()->testAttribute(Qt::WA_QuitOnClose))
876 return false;
877
879}
880
882{
883 Q_Q(const QWidgetWindow);
884
885 // Widget windows may have Qt::WA_DontShowOnScreen, in which case the
886 // QQWidget will be visible, but the corresponding QWindow will not.
887 // Since the lastWindowClosed logic relies on checking whether the
888 // closed window was visible, and if there are any remaining visible
889 // windows, we need to reflect the QWidget state, not the QWindow one.
890 return q->widget()->isVisible();
891}
892
893#if QT_CONFIG(wheelevent)
894
895void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
896{
897 if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
898 return;
899
900 QWidget *rootWidget = m_widget;
901 QPointF pos = event->position();
902
903 // Use proper popup window for wheel event. Some QPA sends the wheel
904 // event to the root menu, so redirect it to the proper popup window.
905 QWidget *activePopupWidget = QApplication::activePopupWidget();
906 if (activePopupWidget && activePopupWidget != m_widget) {
907 rootWidget = activePopupWidget;
908 pos = rootWidget->mapFromGlobal(event->globalPosition());
909 }
910
911 // which child should have it?
912 QWidget *widget = rootWidget->childAt(pos.toPoint());
913
914 if (!widget)
915 widget = rootWidget;
916
917 QPointF mapped = widget->mapFrom(rootWidget, pos);
918
919 QWheelEvent translated(mapped, event->globalPosition(), event->pixelDelta(), event->angleDelta(),
920 event->buttons(), event->modifiers(), event->phase(), event->inverted(),
921 event->source(), event->pointingDevice());
922 translated.setTimestamp(event->timestamp());
923 QGuiApplication::forwardEvent(widget, &translated, event);
924}
925
926#endif // QT_CONFIG(wheelevent)
927
928#if QT_CONFIG(draganddrop)
929
930static QWidget *findDnDTarget(QWidget *parent, const QPoint &pos)
931{
932 // Find a target widget under mouse that accepts drops (QTBUG-22987).
933 QWidget *widget = parent->childAt(pos);
934 if (!widget)
935 widget = parent;
936 for ( ; widget && !widget->isWindow() && !widget->acceptDrops(); widget = widget->parentWidget()) ;
937 if (widget && !widget->acceptDrops())
938 widget = nullptr;
939 return widget;
940}
941
942void QWidgetWindow::handleDragEnterEvent(QDragEnterEvent *event, QWidget *widget)
943{
944 Q_ASSERT(m_dragTarget == nullptr);
945 if (!widget)
946 widget = findDnDTarget(m_widget, event->position().toPoint());
947 if (!widget) {
948 event->ignore();
949 return;
950 }
951 m_dragTarget = widget;
952
953 const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->position().toPoint()));
954 QDragEnterEvent translated(mapped, event->possibleActions(), event->mimeData(),
955 event->buttons(), event->modifiers());
956 QGuiApplication::forwardEvent(m_dragTarget, &translated, event);
957 event->setAccepted(translated.isAccepted());
958 event->setDropAction(translated.dropAction());
959}
960
961void QWidgetWindow::handleDragMoveEvent(QDragMoveEvent *event)
962{
963 QPointer<QWidget> widget = findDnDTarget(m_widget, event->position().toPoint());
964 if (!widget) {
965 event->ignore();
966 if (m_dragTarget) { // Send DragLeave to previous
967 QDragLeaveEvent leaveEvent;
968 QWidget *dragTarget = m_dragTarget;
969 m_dragTarget = nullptr;
970 QGuiApplication::forwardEvent(dragTarget, &leaveEvent, event);
971 }
972 } else {
973 const QPoint mapped = widget->mapFromGlobal(m_widget->mapToGlobal(event->position().toPoint()));
974 QDragMoveEvent translated(mapped, event->possibleActions(), event->mimeData(),
975 event->buttons(), event->modifiers());
976
977 if (widget == m_dragTarget) { // Target widget unchanged: Send DragMove
978 translated.setDropAction(event->dropAction());
979 translated.setAccepted(event->isAccepted());
980 QGuiApplication::forwardEvent(m_dragTarget, &translated, event);
981 } else {
982 if (m_dragTarget) { // Send DragLeave to previous
983 QDragLeaveEvent leaveEvent;
984 QWidget *dragTarget = m_dragTarget;
985 m_dragTarget = nullptr;
986 QGuiApplication::forwardEvent(dragTarget, &leaveEvent, event);
987 }
988 // widget might have been deleted when handling the leaveEvent
989 if (widget) {
990 // Send DragEnter to new widget.
991 handleDragEnterEvent(static_cast<QDragEnterEvent*>(event), widget);
992 // Handling 'DragEnter' should suffice for the application.
993 translated.setDropAction(event->dropAction());
994 translated.setAccepted(event->isAccepted());
995 // The drag enter event is always immediately followed by a drag move event,
996 // see QDragEnterEvent documentation.
997 if (m_dragTarget)
998 QGuiApplication::forwardEvent(m_dragTarget, &translated, event);
999 }
1000 }
1001 event->setAccepted(translated.isAccepted());
1002 event->setDropAction(translated.dropAction());
1003 }
1004}
1005
1006void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *event)
1007{
1008 if (m_dragTarget) {
1009 QWidget *dragTarget = m_dragTarget;
1010 m_dragTarget = nullptr;
1011 QGuiApplication::forwardEvent(dragTarget, event);
1012 }
1013}
1014
1015void QWidgetWindow::handleDropEvent(QDropEvent *event)
1016{
1017 if (Q_UNLIKELY(m_dragTarget.isNull())) {
1018 qWarning() << m_widget << ": No drag target set.";
1019 event->ignore();
1020 return;
1021 }
1022 const QPoint mapped = m_dragTarget->mapFromGlobal(m_widget->mapToGlobal(event->position().toPoint()));
1023 QDropEvent translated(mapped, event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
1024 QWidget *dragTarget = m_dragTarget;
1025 m_dragTarget = nullptr;
1026 QGuiApplication::forwardEvent(dragTarget, &translated, event);
1027 event->setAccepted(translated.isAccepted());
1028 event->setDropAction(translated.dropAction());
1029}
1030
1031#endif // QT_CONFIG(draganddrop)
1032
1034{
1036 return; // Ignore for widgets that fake exposure
1037
1038 QWidgetPrivate *wPriv = m_widget->d_func();
1039 const bool exposed = isExposed();
1040
1041 if (wPriv->childrenHiddenByWState) {
1042 // If widgets has been previously hidden by window state change event
1043 // and they aren't yet shown...
1044 if (exposed) {
1045 // If the window becomes exposed...
1046 if (!wPriv->childrenShownByExpose) {
1047 // ... and they haven't been shown by this function yet - show it.
1048 wPriv->showChildren(true);
1050 QCoreApplication::forwardEvent(m_widget, &showEvent, event);
1051 wPriv->childrenShownByExpose = true;
1052 }
1053 } else {
1054 // If the window becomes not exposed...
1055 if (wPriv->childrenShownByExpose) {
1056 // ... and child widgets was previously shown by the expose event - hide widgets again.
1057 // This is a workaround, because sometimes when window is minimized programmatically,
1058 // the QPA can notify that the window is exposed after changing window state to minimized
1059 // and then, the QPA can send next expose event with null exposed region (not exposed).
1060 wPriv->hideChildren(true);
1062 QCoreApplication::forwardEvent(m_widget, &hideEvent, event);
1063 wPriv->childrenShownByExpose = false;
1064 }
1065 }
1066 }
1067
1068 if (exposed) {
1069 // QTBUG-39220, QTBUG-58575: set all (potentially fully obscured parent widgets) mapped.
1070 m_widget->setAttribute(Qt::WA_Mapped);
1071 for (QWidget *p = m_widget->parentWidget(); p && !p->testAttribute(Qt::WA_Mapped); p = p->parentWidget())
1072 p->setAttribute(Qt::WA_Mapped);
1073 if (!event->m_region.isNull())
1074 wPriv->syncBackingStore(event->m_region);
1075 } else {
1076 m_widget->setAttribute(Qt::WA_Mapped, false);
1077 }
1078}
1079
1081{
1082 // QWindow does currently not know 'active'.
1083 Qt::WindowStates eventState = event->oldState();
1084 Qt::WindowStates widgetState = m_widget->windowState();
1085 Qt::WindowStates windowState = windowStates();
1086 if (widgetState & Qt::WindowActive)
1087 eventState |= Qt::WindowActive;
1088
1089 // Determine the new widget state, remember maximized/full screen
1090 // during minimized.
1091 if (windowState & Qt::WindowMinimized) {
1092 widgetState |= Qt::WindowMinimized;
1093 } else {
1094 widgetState = windowState | (widgetState & Qt::WindowActive);
1095 if (windowState) // Maximized or FullScreen
1096 updateNormalGeometry();
1097 }
1098
1099 // Sent event if the state changed (that is, it is not triggered by
1100 // QWidget::setWindowState(), which also sends an event to the widget).
1101 if (widgetState != Qt::WindowStates::Int(m_widget->data->window_state)) {
1102 m_widget->data->window_state = uint(widgetState);
1103 QWindowStateChangeEvent widgetEvent(eventState);
1104 QGuiApplication::forwardEvent(m_widget, &widgetEvent, event);
1105 }
1106}
1107
1109{
1110 return m_widget->nativeEvent(eventType, message, result);
1111}
1112
1113#if QT_CONFIG(tabletevent)
1114void QWidgetWindow::handleTabletEvent(QTabletEvent *event)
1115{
1116 static QPointer<QWidget> qt_tablet_target = nullptr;
1117
1118 QWidget *widget = qt_tablet_target;
1119
1120 if (!widget) {
1121 widget = m_widget->childAt(event->position().toPoint());
1122 if (!widget)
1123 widget = m_widget;
1124 if (event->type() == QEvent::TabletPress)
1125 qt_tablet_target = widget;
1126 }
1127
1128 if (widget) {
1129 QPointF delta = event->globalPosition() - event->globalPosition().toPoint();
1130 QPointF mapped = widget->mapFromGlobal(event->globalPosition().toPoint()) + delta;
1131 QTabletEvent ev(event->type(), event->pointingDevice(), mapped, event->globalPosition(),
1132 event->pressure(), event->xTilt(), event->yTilt(), event->tangentialPressure(),
1133 event->rotation(), event->z(), event->modifiers(), event->button(), event->buttons());
1134 ev.setTimestamp(event->timestamp());
1135 ev.setAccepted(false);
1136 QGuiApplication::forwardEvent(widget, &ev, event);
1137 event->setAccepted(ev.isAccepted());
1138 }
1139
1140 if (event->type() == QEvent::TabletRelease && event->buttons() == Qt::NoButton)
1141 qt_tablet_target = nullptr;
1142}
1143#endif // QT_CONFIG(tabletevent)
1144
1145#ifndef QT_NO_GESTURES
1147{
1148 // copy-pasted code to find correct widget follows:
1149 QObject *receiver = nullptr;
1152 QWidget *popupFocusWidget = popup->focusWidget();
1153 receiver = popupFocusWidget ? popupFocusWidget : popup;
1154 }
1155 if (!receiver)
1156 receiver = QApplication::widgetAt(e->globalPosition().toPoint());
1157 if (!receiver)
1158 receiver = m_widget; // last resort
1159
1160 QApplication::forwardEvent(receiver, e);
1161}
1162#endif // QT_NO_GESTURES
1163
1164#ifndef QT_NO_CONTEXTMENU
1166{
1167 // We are only interested in keyboard originating context menu events here,
1168 // mouse originated context menu events for widgets are generated in mouse handling methods.
1170 return;
1171
1173 if (!fw) {
1175 fw = (QApplication::activePopupWidget()->focusWidget()
1176 ? QApplication::activePopupWidget()->focusWidget()
1178 } else if (QApplication::focusWidget()) {
1180 } else {
1181 fw = m_widget;
1182 }
1183 }
1184 if (fw && fw->isEnabled()) {
1185 QPoint pos = fw->inputMethodQuery(Qt::ImCursorRectangle).toRect().center();
1187 e->modifiers());
1188 QGuiApplication::forwardEvent(fw, &widgetEvent, e);
1189 }
1190}
1191#endif // QT_NO_CONTEXTMENU
1192
1193void QWidgetWindow::updateObjectName()
1194{
1195 QString name = m_widget->objectName();
1196 if (name.isEmpty())
1197 name = QString::fromUtf8(m_widget->metaObject()->className()) + "Class"_L1;
1198 name += "Window"_L1;
1200}
1201
1203
1204#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 isBlockedByModal(QWidget *widget)
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 void setEventSpontaneous(QEvent *e, bool spontaneous)
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.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
\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
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 QPlatformIntegration * platformIntegration()
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:73
\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:6018
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:4333
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:4313
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:6845
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:6683
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:6859
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6828
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:9913
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.
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:4229
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:2888
bool isVisible() const
Definition qwidget.h:874
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition qwidget.h:801
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:343
virtual bool participatesInLastWindowClosed() const
Definition qwindow.cpp:2378
\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:2222
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:2511
virtual void hideEvent(QHideEvent *)
Override this to handle hide events (ev).
Definition qwindow.cpp:2486
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:2475
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
@ Popup
Definition qnamespace.h:211
FocusReason
@ BacktabFocusReason
@ TabFocusReason
int openPopupCount
bool qt_replay_popup_mouse_event
bool qt_popup_down_closed
QWidget * qt_popup_down
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:166
#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
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
ptrdiff_t qintptr
Definition qtypes.h:166
#define leave(x)
Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
bool q_evaluateRhiConfig(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1122
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786
int openPopupCount
bool qt_replay_popup_mouse_event
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:1122
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
QWidget * win
Definition settings.cpp:6
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
QT_BEGIN_NAMESPACE bool toBool(const QString &str)
Definition utils.h:14