Browse Source

QWindow clear color set to transparent

All windows close together
Donald Carr 7 years ago
parent
commit
6cc99231a9
2 changed files with 24 additions and 1 deletions
  1. 2 0
      qml/main.qml
  2. 22 1
      src/main.cpp

+ 2 - 0
qml/main.qml

@@ -165,4 +165,6 @@ Item {
             }
         }
     }
+
+    Component.onCompleted: appWindow.setFocus()
 }

+ 22 - 1
src/main.cpp

@@ -40,6 +40,25 @@
 #include <QFileSystemWatcher>
 #include <QtPlugin>
 
+class CloseEventFilter : public QObject
+{
+    Q_OBJECT
+public:
+    CloseEventFilter(QObject *p) : QObject(p) { /**/ }
+
+protected:
+    bool eventFilter(QObject *obj, QEvent *event);
+};
+
+bool CloseEventFilter::eventFilter(QObject *obj, QEvent *event)
+{
+    if (event->type() == QEvent::Close) {
+        qApp->quit();
+    }
+
+    return QObject::eventFilter(obj, event);
+}
+
 class NativeUtils : public QObject {
     Q_OBJECT
     Q_PROPERTY(bool rebootRequired MEMBER rebootRequired NOTIFY rebootRequiredChanged)
@@ -100,8 +119,9 @@ QQuickView* ArtView::artView()
         sharedQmlEngine->addImportPath(qmlPath);
         sharedQmlEngine->rootContext()->setContextProperty("nativeUtils", new NativeUtils(sharedQmlEngine));
         sharedQmlEngine->rootContext()->setContextProperty("imageModel", new PictureModel(sharedQmlEngine));
-
+        QObject::connect(sharedQmlEngine, &QQmlEngine::quit, qApp, &QCoreApplication::quit);
     }
+    view->setColor(Qt::transparent);
     view->setResizeMode(QQuickView::SizeRootObjectToView);
     view->setSource(QUrl(qmlPath + "/main.qml"));
     return view;
@@ -119,6 +139,7 @@ int main(int argc, char *argv[])
     QGuiApplication app(argc, argv);
     app.setOrganizationName("Chaos Reins");
     app.setApplicationName("artriculate");
+    app.installEventFilter(new CloseEventFilter(&app));
 
     QSettings settings;