Created
February 5, 2018 11:14
-
-
Save mitchcurtis/f13ba43d47391a346b73571a95e956df to your computer and use it in GitHub Desktop.
Using QScreen in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
#include <QScreen> | |
#include <QDebug> | |
int main(int argc, char *argv[]) | |
{ | |
#if defined(Q_OS_WIN) | |
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | |
#endif | |
QGuiApplication app(argc, argv); | |
QQmlApplicationEngine engine; | |
QScreen *firstScreen = app.screens().first(); | |
engine.globalObject().setProperty("firstScreen", engine.newQObject(firstScreen)); | |
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); | |
if (engine.rootObjects().isEmpty()) | |
return -1; | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.9 | |
import QtQuick.Controls 2.2 | |
import "test.js" as Test | |
ApplicationWindow { | |
visible: true | |
width: 640 | |
height: 480 | |
title: qsTr("Hello World") | |
Component.onCompleted: Test.func() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function func() { | |
print(firstScreen.availableVirtualGeometry) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment