Skip to content

Instantly share code, notes, and snippets.

@mitchcurtis
Created February 5, 2018 11:14
Show Gist options
  • Save mitchcurtis/f13ba43d47391a346b73571a95e956df to your computer and use it in GitHub Desktop.
Save mitchcurtis/f13ba43d47391a346b73571a95e956df to your computer and use it in GitHub Desktop.
Using QScreen in JavaScript
#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();
}
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()
}
function func() {
print(firstScreen.availableVirtualGeometry)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment