From c6271071b4d0686fef8fe3df215ce84be0305a8b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 28 Sep 2012 17:14:44 +0200 Subject: [PATCH] QPA/Windows example: Set proper window flags, titles, names. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not leak windows. Change-Id: I3af29ce597742cbe6444208aa72443c0507819db Reviewed-by: Samuel Rødal Reviewed-by: Miikka Heikkinen --- examples/qpa/windows/main.cpp | 16 ++++++++++++++-- examples/qpa/windows/window.cpp | 7 +++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/qpa/windows/main.cpp b/examples/qpa/windows/main.cpp index 2e03d1d57b..da189ab447 100644 --- a/examples/qpa/windows/main.cpp +++ b/examples/qpa/windows/main.cpp @@ -41,35 +41,47 @@ #include #include #include +#include #include "window.h" int main(int argc, char **argv) { + typedef QSharedPointer WindowPtr; + QGuiApplication app(argc, argv); Window a; + a.setFramePos(QPoint(10, 10)); + a.setWindowTitle(QStringLiteral("Window A")); + a.setObjectName(a.windowTitle()); a.setVisible(true); Window b; + b.setFramePos(QPoint(100, 100)); + b.setWindowTitle(QStringLiteral("Window B")); + b.setObjectName(b.windowTitle()); b.setVisible(true); Window child(&b); + child.setObjectName(QStringLiteral("ChildOfB")); child.setVisible(true); // create one window on each additional screen as well QList screens = app.screens(); + QList windows; foreach (QScreen *screen, screens) { if (screen == app.primaryScreen()) continue; - Window *window = new Window(screen); + WindowPtr window(new Window(screen)); QRect geometry = window->geometry(); geometry.moveCenter(screen->availableGeometry().center()); window->setGeometry(geometry); window->setVisible(true); window->setWindowTitle(screen->name()); + window->setObjectName(window->windowTitle()); + windows.push_back(window); } - return app.exec(); } diff --git a/examples/qpa/windows/window.cpp b/examples/qpa/windows/window.cpp index 664f74b651..a9f29274ac 100644 --- a/examples/qpa/windows/window.cpp +++ b/examples/qpa/windows/window.cpp @@ -73,10 +73,13 @@ void Window::initialize() if (parent()) setGeometry(QRect(160, 120, 320, 240)); else { - setGeometry(QRect(10, 10, 640, 480)); + setWindowFlags(windowFlags() | Qt::WindowTitleHint | Qt::WindowSystemMenuHint + | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); + const QSize baseSize = QSize(640, 480); + setGeometry(QRect(geometry().topLeft(), baseSize)); setSizeIncrement(QSize(10, 10)); - setBaseSize(QSize(640, 480)); + setBaseSize(baseSize); setMinimumSize(QSize(240, 160)); setMaximumSize(QSize(800, 600)); }