本文整理汇总了C++中QWindow::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ QWindow::parent方法的具体用法?C++ QWindow::parent怎么用?C++ QWindow::parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWindow
的用法示例。
在下文中一共展示了QWindow::parent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleEnterLeaveEvent
void QWidgetWindow::handleEnterLeaveEvent(QEvent *event)
{
#if !defined(Q_OS_OSX) && !defined(Q_OS_IOS) // Cocoa tracks popups
// Ignore all enter/leave events from QPA if we are not on the first-level context menu.
// This prevents duplicated events on most platforms. Fake events will be delivered in
// QWidgetWindow::handleMouseEvent(QMouseEvent *). Make an exception whether the widget
// is already under mouse - let the mouse leave.
if (QApplicationPrivate::inPopupMode() && m_widget != QApplication::activePopupWidget() && !m_widget->underMouse())
return;
#endif
if (event->type() == QEvent::Leave) {
QWidget *enter = 0;
// Check from window system event queue if the next queued enter targets a window
// in the same window hierarchy (e.g. enter a child of this window). If so,
// remove the enter event from queue and handle both in single dispatch.
QWindowSystemInterfacePrivate::EnterEvent *systemEvent =
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>
(QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::Enter));
const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QGuiApplicationPrivate::lastCursorPosition;
if (systemEvent) {
if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter))
{
QWindow *thisParent = this;
QWindow *enterParent = enterWindow;
while (thisParent->parent())
thisParent = thisParent->parent();
while (enterParent->parent())
enterParent = enterParent->parent();
if (thisParent == enterParent) {
QGuiApplicationPrivate::currentMouseWindow = enterWindow;
enter = enterWindow->widget();
QWindowSystemInterfacePrivate::removeWindowSystemEvent(systemEvent);
}
}
}
// Enter-leave between sibling widgets is ignored when there is a mousegrabber - this makes
// both native and non-native widgets work similarly.
// When mousegrabbing, leaves are only generated if leaving the parent window.
if (!enter || !QWidget::mouseGrabber()) {
// Preferred leave target is the last mouse receiver, unless it has native window,
// in which case it is assumed to receive it's own leave event when relevant.
QWidget *leave = m_widget;
if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
leave = qt_last_mouse_receiver.data();
QApplicationPrivate::dispatchEnterLeave(enter, leave, globalPosF);
qt_last_mouse_receiver = enter;
}
} else {
const QEnterEvent *ee = static_cast<QEnterEvent *>(event);
QWidget *child = m_widget->childAt(ee->pos());
QWidget *receiver = child ? child : m_widget.data();
QApplicationPrivate::dispatchEnterLeave(receiver, 0, ee->screenPos());
qt_last_mouse_receiver = receiver;
}
}
示例2: handleEnterLeaveEvent
void QWidgetWindow::handleEnterLeaveEvent(QEvent *event)
{
if (event->type() == QEvent::Leave) {
QWidget *enter = 0;
// Check from window system event queue if the next queued enter targets a window
// in the same window hierarchy (e.g. enter a child of this window). If so,
// remove the enter event from queue and handle both in single dispatch.
QWindowSystemInterfacePrivate::EnterEvent *systemEvent =
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>
(QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::Enter));
const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QGuiApplicationPrivate::lastCursorPosition;
if (systemEvent) {
if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter))
{
QWindow *thisParent = this;
QWindow *enterParent = enterWindow;
while (thisParent->parent())
thisParent = thisParent->parent();
while (enterParent->parent())
enterParent = enterParent->parent();
if (thisParent == enterParent) {
QGuiApplicationPrivate::currentMouseWindow = enterWindow;
enter = enterWindow->widget();
QWindowSystemInterfacePrivate::removeWindowSystemEvent(systemEvent);
}
}
}
// Enter-leave between sibling widgets is ignored when there is a mousegrabber - this makes
// both native and non-native widgets work similarly.
// When mousegrabbing, leaves are only generated if leaving the parent window.
if (!enter || !QWidget::mouseGrabber()) {
// Preferred leave target is the last mouse receiver, unless it has native window,
// in which case it is assumed to receive it's own leave event when relevant.
QWidget *leave = m_widget;
if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
leave = qt_last_mouse_receiver.data();
QApplicationPrivate::dispatchEnterLeave(enter, leave, globalPosF);
qt_last_mouse_receiver = enter;
}
} else {
const QEnterEvent *ee = static_cast<QEnterEvent *>(event);
QWidget *child = m_widget->childAt(ee->pos());
QWidget *receiver = child ? child : m_widget;
QApplicationPrivate::dispatchEnterLeave(receiver, 0, ee->screenPos());
qt_last_mouse_receiver = receiver;
}
}
示例3: testAncestorChange
void tst_QWindowContainer::testAncestorChange()
{
QWidget root;
QWidget *left = new QWidget(&root);
QWidget *right = new QWidget(&root);
root.setGeometry(0, 0, 200, 100);
left->setGeometry(0, 0, 100, 100);
right->setGeometry(100, 0, 100, 100);
QWindow *window = new QWindow();
QWidget *container = QWidget::createWindowContainer(window, left);
container->setGeometry(0, 0, 100, 100);
// Root
// + left
// | + container
// | + window
// + right
root.show();
QVERIFY(QTest::qWaitForWindowExposed(&root));
QCOMPARE(window->geometry(), QRect(0, 0, 100, 100));
container->setParent(right);
// Root
// + left
// + right
// + container
// + window
QCOMPARE(window->geometry(), QRect(100, 0, 100, 100));
QWidget *newRoot = new QWidget(&root);
newRoot->setGeometry(50, 50, 200, 200);
right->setParent(newRoot);
// Root
// + left
// + newRoot
// + right
// + container
// + window
QCOMPARE(window->geometry(), QRect(150, 50, 100, 100));
newRoot->move(0, 0);
QCOMPARE(window->geometry(), QRect(100, 0, 100, 100));
newRoot->setParent(0);
newRoot->setGeometry(100, 100, 200, 200);
newRoot->show();
QVERIFY(QTest::qWaitForWindowExposed(newRoot));
QCOMPARE(newRoot->windowHandle(), window->parent());
// newRoot
// + right
// + container
// + window
QCOMPARE(window->geometry(), QRect(100, 0, 100, 100));
}
示例4: postEvent
void QMirClientInput::postEvent(QMirClientWindow *platformWindow, const MirEvent *event)
{
QWindow *window = platformWindow->window();
QCoreApplication::postEvent(this, new UbuntuEvent(
platformWindow, event, mEventType));
if ((window->flags().testFlag(Qt::WindowTransparentForInput)) && window->parent()) {
QCoreApplication::postEvent(this, new UbuntuEvent(
static_cast<QMirClientWindow*>(platformWindow->QPlatformWindow::parent()),
event, mEventType));
}
}
示例5: handleSwipeDown
void QQnxNavigatorEventHandler::handleSwipeDown()
{
qNavigatorEventHandlerDebug() << Q_FUNC_INFO;
QWindow *w = QGuiApplication::focusWindow();
if (w) {
// Get the top level window that is ancestor of the focus window
while (QWindow *parent = w->parent())
w = parent;
QWindowSystemInterface::handlePlatformPanelEvent(w);
}
}
示例6: testDockWidget
void tst_QWindowContainer::testDockWidget()
{
QMainWindow mainWindow;
mainWindow.resize(200, 200);
QDockWidget *dock = new QDockWidget();
QWindow *window = new QWindow();
QWidget *container = QWidget::createWindowContainer(window);
dock->setWidget(container);
mainWindow.addDockWidget(Qt::RightDockWidgetArea, dock);
mainWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&mainWindow));
QVERIFY(window->parent() == mainWindow.window()->windowHandle());
QTest::qWait(1000);
dock->setFloating(true);
QTRY_VERIFY(window->parent() != mainWindow.window()->windowHandle());
QTest::qWait(1000);
dock->setFloating(false);
QTRY_VERIFY(window->parent() == mainWindow.window()->windowHandle());
}
示例7: qWidgetShortcutContextMatcher
/*! \internal
Returns true if the widget \a w is a logical sub window of the current
top-level widget.
*/
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
{
Q_ASSERT_X(object, "QShortcutMap", "Shortcut has no owner. Illegal map state!");
QWidget *active_window = QApplication::activeWindow();
// popups do not become the active window,
// so we fake it here to get the correct context
// for the shortcut system.
if (QApplication::activePopupWidget())
active_window = QApplication::activePopupWidget();
if (!active_window) {
QWindow *qwindow = QGuiApplication::focusWindow();
if (qwindow && qwindow->isActive()) {
while (qwindow) {
QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(qwindow);
if (widgetWindow) {
active_window = widgetWindow->widget();
break;
}
qwindow = qwindow->parent();
}
}
}
if (!active_window)
return false;
#ifndef QT_NO_ACTION
if (QAction *a = qobject_cast<QAction *>(object))
return correctActionContext(context, a, active_window);
#endif
#ifndef QT_NO_GRAPHICSVIEW
if (QGraphicsWidget *gw = qobject_cast<QGraphicsWidget *>(object))
return correctGraphicsWidgetContext(context, gw, active_window);
#endif
QWidget *w = qobject_cast<QWidget *>(object);
if (!w) {
QShortcut *s = qobject_cast<QShortcut *>(object);
if (s)
w = s->parentWidget();
}
if (!w) {
QWindow *qwindow = qobject_cast<QWindow *>(object);
while (qwindow) {
QWidgetWindow *widget_window = qobject_cast<QWidgetWindow *>(qwindow);
if (widget_window) {
w = widget_window->widget();
break;
}
qwindow = qwindow->parent();
}
}
if (!w)
return false;
return correctWidgetContext(context, w, active_window);
}
示例8: translateMouseEvent
bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
QtWindows::WindowsEventType et,
MSG msg, LRESULT *result)
{
#ifdef Q_COMPILER_CLASS_ENUM
enum : quint64 { signatureMask = 0xffffff00, miWpSignature = 0xff515700 };
#else
static const quint64 signatureMask = 0xffffff00;
static const quint64 miWpSignature = 0xff515700;
#endif // !Q_COMPILER_CLASS_ENUM
if (et == QtWindows::MouseWheelEvent)
return translateMouseWheelEvent(window, hwnd, msg, result);
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized;
// Check for events synthesized from touch. Lower byte is touch index, 0 means pen.
static const bool passSynthesizedMouseEvents =
!(QWindowsIntegration::instance()->options() & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch);
// Check for events synthesized from touch. Lower 7 bits are touch/pen index, bit 8 indicates touch.
// However, when tablet support is active, extraInfo is a packet serial number. This is not a problem
// since we do not want to ignore mouse events coming from a tablet.
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms703320.aspx
const quint64 extraInfo = quint64(GetMessageExtraInfo());
if ((extraInfo & signatureMask) == miWpSignature) {
if (extraInfo & 0x80) { // Bit 7 indicates touch event, else tablet pen.
source = Qt::MouseEventSynthesizedBySystem;
if (!passSynthesizedMouseEvents)
return false;
}
}
const QPoint winEventPosition(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam));
if (et & QtWindows::NonClientEventFlag) {
const QPoint globalPosition = winEventPosition;
const QPoint clientPosition = QWindowsGeometryHint::mapFromGlobal(hwnd, globalPosition);
const Qt::MouseButtons buttons = QWindowsMouseHandler::queryMouseButtons();
QWindowSystemInterface::handleFrameStrutMouseEvent(window, clientPosition,
globalPosition, buttons,
QWindowsKeyMapper::queryKeyboardModifiers(),
source);
return false; // Allow further event processing (dragging of windows).
}
*result = 0;
if (msg.message == WM_MOUSELEAVE) {
qCDebug(lcQpaEvents) << "WM_MOUSELEAVE for " << window << " previous window under mouse = " << m_windowUnderMouse << " tracked window =" << m_trackedWindow;
// When moving out of a window, WM_MOUSEMOVE within the moved-to window is received first,
// so if m_trackedWindow is not the window here, it means the cursor has left the
// application.
if (window == m_trackedWindow) {
QWindow *leaveTarget = m_windowUnderMouse ? m_windowUnderMouse : m_trackedWindow;
qCDebug(lcQpaEvents) << "Generating leave event for " << leaveTarget;
QWindowSystemInterface::handleLeaveEvent(leaveTarget);
m_trackedWindow = 0;
m_windowUnderMouse = 0;
}
return true;
}
QWindowsWindow *platformWindow = static_cast<QWindowsWindow *>(window->handle());
const Qt::MouseButtons buttons = keyStateToMouseButtons(int(msg.wParam));
// If the window was recently resized via mouse doubleclick on the frame or title bar,
// we don't get WM_LBUTTONDOWN or WM_LBUTTONDBLCLK for the second click,
// but we will get at least one WM_MOUSEMOVE with left button down and the WM_LBUTTONUP,
// which will result undesired mouse press and release events.
// To avoid those, we ignore any events with left button down if we didn't
// get the original WM_LBUTTONDOWN/WM_LBUTTONDBLCLK.
if (msg.message == WM_LBUTTONDOWN || msg.message == WM_LBUTTONDBLCLK) {
m_leftButtonDown = true;
} else {
const bool actualLeftDown = buttons & Qt::LeftButton;
if (!m_leftButtonDown && actualLeftDown) {
// Autocapture the mouse for current window to and ignore further events until release.
// Capture is necessary so we don't get WM_MOUSELEAVEs to confuse matters.
// This autocapture is released normally when button is released.
if (!platformWindow->hasMouseCapture()) {
platformWindow->applyCursor();
platformWindow->setMouseGrabEnabled(true);
platformWindow->setFlag(QWindowsWindow::AutoMouseCapture);
qCDebug(lcQpaEvents) << "Automatic mouse capture for missing buttondown event" << window;
}
m_previousCaptureWindow = window;
return true;
} else if (m_leftButtonDown && !actualLeftDown) {
m_leftButtonDown = false;
}
}
const QPoint globalPosition = QWindowsGeometryHint::mapToGlobal(hwnd, winEventPosition);
// In this context, neither an invisible nor a transparent window (transparent regarding mouse
// events, "click-through") can be considered as the window under mouse.
QWindow *currentWindowUnderMouse = platformWindow->hasMouseCapture() ?
QWindowsScreen::windowAt(globalPosition, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT) : window;
while (currentWindowUnderMouse && currentWindowUnderMouse->flags() & Qt::WindowTransparentForInput)
currentWindowUnderMouse = currentWindowUnderMouse->parent();
// QTBUG-44332: When Qt is running at low integrity level and
// a Qt Window is parented on a Window of a higher integrity process
//.........这里部分代码省略.........