QPA/Windows example: Set proper window flags, titles, names.

Do not leak windows.

Change-Id: I3af29ce597742cbe6444208aa72443c0507819db
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
This commit is contained in:
Friedemann Kleint 2012-09-28 17:14:44 +02:00 committed by The Qt Project
parent af83eecd76
commit c6271071b4
2 changed files with 19 additions and 4 deletions

View File

@ -41,35 +41,47 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QScreen> #include <QScreen>
#include <QRect> #include <QRect>
#include <QSharedPointer>
#include "window.h" #include "window.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
typedef QSharedPointer<QWindow> WindowPtr;
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
Window a; Window a;
a.setFramePos(QPoint(10, 10));
a.setWindowTitle(QStringLiteral("Window A"));
a.setObjectName(a.windowTitle());
a.setVisible(true); a.setVisible(true);
Window b; Window b;
b.setFramePos(QPoint(100, 100));
b.setWindowTitle(QStringLiteral("Window B"));
b.setObjectName(b.windowTitle());
b.setVisible(true); b.setVisible(true);
Window child(&b); Window child(&b);
child.setObjectName(QStringLiteral("ChildOfB"));
child.setVisible(true); child.setVisible(true);
// create one window on each additional screen as well // create one window on each additional screen as well
QList<QScreen *> screens = app.screens(); QList<QScreen *> screens = app.screens();
QList<WindowPtr> windows;
foreach (QScreen *screen, screens) { foreach (QScreen *screen, screens) {
if (screen == app.primaryScreen()) if (screen == app.primaryScreen())
continue; continue;
Window *window = new Window(screen); WindowPtr window(new Window(screen));
QRect geometry = window->geometry(); QRect geometry = window->geometry();
geometry.moveCenter(screen->availableGeometry().center()); geometry.moveCenter(screen->availableGeometry().center());
window->setGeometry(geometry); window->setGeometry(geometry);
window->setVisible(true); window->setVisible(true);
window->setWindowTitle(screen->name()); window->setWindowTitle(screen->name());
window->setObjectName(window->windowTitle());
windows.push_back(window);
} }
return app.exec(); return app.exec();
} }

View File

@ -73,10 +73,13 @@ void Window::initialize()
if (parent()) if (parent())
setGeometry(QRect(160, 120, 320, 240)); setGeometry(QRect(160, 120, 320, 240));
else { 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)); setSizeIncrement(QSize(10, 10));
setBaseSize(QSize(640, 480)); setBaseSize(baseSize);
setMinimumSize(QSize(240, 160)); setMinimumSize(QSize(240, 160));
setMaximumSize(QSize(800, 600)); setMaximumSize(QSize(800, 600));
} }