void QWidgetPrivate::show_sys() { Q_Q(QWidget); QWindow *window = q->windowHandle(); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { invalidateBuffer(q->rect()); q->setAttribute(Qt::WA_Mapped); if (q->isWindow() && q->windowModality() != Qt::NonModal && window) { // add our window to the modal window list QGuiApplicationPrivate::showModalWindow(window); } return; } QApplication::postEvent(q, new QUpdateLaterEvent(q->rect())); if (!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow)) return; if (window) { if (q->isWindow()) fixPosIncludesFrame(); QRect geomRect = q->geometry(); if (!q->isWindow()) { QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint()); geomRect.moveTopLeft(topLeftOfWindow); } const QRect windowRect = window->geometry(); if (windowRect != geomRect) { if (q->testAttribute(Qt::WA_Moved)) window->setGeometry(geomRect); else window->resize(geomRect.size()); } if (QBackingStore *store = q->backingStore()) { if (store->size() != geomRect.size()) { store->resize(geomRect.size()); } } #ifndef QT_NO_CURSOR qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show #endif invalidateBuffer(q->rect()); window->setVisible(true); // Was the window moved by the Window system or QPlatformWindow::initialGeometry() ? if (window->isTopLevel()) { const QPoint crectTopLeft = q->data->crect.topLeft(); const QPoint windowTopLeft = window->geometry().topLeft(); if (crectTopLeft == QPoint(0, 0) && windowTopLeft != crectTopLeft) q->data->crect.moveTopLeft(windowTopLeft); } } }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QSurfaceFormat format; format.setSamples(16); QWindow root; root.resize(640 * 2, 480); QQuickView viewL(&root); viewL.setFormat(format); viewL.setSource(QUrl("qrc:///qml/tst_qrc.qml")); viewL.setGeometry(0, 0, 640, 480); QQuickView viewR(&root); viewR.setFormat(format); viewR.setSource(QUrl("Qrc:///qml/tst_qrc.qml")); viewR.setGeometry(640, 0, 640, 480); root.show(); return app.exec(); }
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) { Q_Q(QWidget); Q_UNUSED(window); Q_UNUSED(initializeWindow); Q_UNUSED(destroyOldWindow); Qt::WindowFlags flags = data.window_flags; if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow()) return; // we only care about real toplevels QWindow *win = topData()->window; // topData() ensures the extra is created but does not ensure 'window' is non-null // in case the extra was already valid. if (!win) { createTLSysExtra(); win = topData()->window; } win->setFlags(data.window_flags); fixPosIncludesFrame(); if (q->testAttribute(Qt::WA_Moved)) win->setGeometry(q->geometry()); else win->resize(q->size()); win->setScreen(QGuiApplication::screens().value(topData()->screenIndex, 0)); if (q->testAttribute(Qt::WA_TranslucentBackground)) { QSurfaceFormat format; format.setAlphaBufferSize(8); win->setFormat(format); } if (QWidget *nativeParent = q->nativeParentWidget()) { if (nativeParent->windowHandle()) { if (flags & Qt::Window) { win->setTransientParent(nativeParent->windowHandle()); win->setParent(0); } else { win->setTransientParent(0); win->setParent(nativeParent->windowHandle()); } } } qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ? QWindowPrivate::WindowFrameInclusive : QWindowPrivate::WindowFrameExclusive; win->create(); // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing. if ((flags & Qt::Desktop) == Qt::Window) win->handle()->setFrameStrutEventsEnabled(true); data.window_flags = win->flags(); QBackingStore *store = q->backingStore(); if (!store) { if (win && q->windowType() != Qt::Desktop) q->setBackingStore(new QBackingStore(win)); else q->setAttribute(Qt::WA_PaintOnScreen, true); } setWindowModified_helper(); setWinId(win->winId()); // Check children and create windows for them if necessary q_createNativeChildrenAndSetParent(q); if (extra && !extra->mask.isEmpty()) setMask_sys(extra->mask); // If widget is already shown, set window visible, too if (q->isVisible()) win->setVisible(true); }