#include <QtGui/QGuiApplication>
#include <QtQuick/qquickview.h>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeEngine>
#include "minehunt.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQuickView canvas;
canvas.setWindowFlags(Qt::FramelessWindowHint);
qmlRegisterType<TileData>();
MinehuntGame* game = new MinehuntGame();
canvas.setResizeMode(QQuickView::SizeRootObjectToView);
canvas.engine()->rootContext()->setContextObject(game);
canvas.setSource(QString("qrc:///minehunt.qml"));
QObject::connect(canvas.engine(), SIGNAL(quit()), &app, SLOT(quit()));
canvas.showFullScreen();
return app.exec();
}
import QtQuick 2.0import "MinehuntCore" 2.0Item{
id: root
width: 1920
height: 1080
Item {id: fieldproperty int clickx: 0property int clicky: 0width: 450; height: 450Image { source: "MinehuntCore/pics/background.png"; anchors.fill: parent; fillMode: Image.Tile }Grid {anchors.horizontalCenter: parent.horizontalCentercolumns: 9; spacing: 1Repeater {id: repeatermodel: tilesdelegate: Tile {}}
}
Row {id: gamedatax: 20; spacing: 20anchors.bottom: field.bottom; anchors.bottomMargin: 15Image {source: "MinehuntCore/pics/quit.png"scale: quitMouse.pressed ? 0.8 : 1.0smooth: quitMouse.pressedy: 10MouseArea {id: quitMouseanchors.fill: parentanchors.margins: -20onClicked: Qt.quit()}
}
Column {spacing: 2Image { source: "MinehuntCore/pics/bomb-color.png" }Text { anchors.horizontalCenter: parent.horizontalCenter; color: "white"; text: numMines }}
Column {spacing: 2Image { source: "MinehuntCore/pics/flag-color.png" }Text { anchors.horizontalCenter: parent.horizontalCenter; color: "white"; text: numFlags }}
}
Image {anchors.bottom: field.bottom; anchors.bottomMargin: 15anchors.right: field.right; anchors.rightMargin: 20source: isPlaying ? 'MinehuntCore/pics/face-smile.png' :hasWon ? 'MinehuntCore/pics/face-smile-big.png': 'MinehuntCore/pics/face-sad.png'MouseArea { anchors.fill: parent; onPressed: reset() }}
Text {anchors.centerIn: parent; width: parent.width - 20horizontalAlignment: Text.AlignHCenterwrapMode: Text.WordWraptext: "Minehunt demo has to be compiled to run.\n\nPlease see README."color: "white"; font.bold: true; font.pixelSize: 14visible: tiles == undefined}
}}
This sounds like it needs to be solved at the QQuickCanvas-level
somehow. Translucency in Qt 5 should work simply by setting a non-zero
alpha in the QSurfaceFormat of the QWindow, and making sure to first
clear the background with transparent.
--
Samuel
_______________________________________________
Development mailing list
Devel...@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
QSurfaceFormat surfaceFormat;
surfaceFormat.setAlphaBufferSize(1000);
canvas.setFormat(surfaceFormat);
canvas.setClearBeforeRendering(true);
canvas.setClearColor(QColor(Qt::transparent));
canvas.setWindowFlags(Qt::FramelessWindowHint);
Should probably be surfaceFormat.setAlphaBufferSize(8); as I'm not sure
if it bails out when it can't find a configuration with at minimum the
requested buffer size at the moment.
> canvas.setFormat(surfaceFormat);
>
> canvas.setClearBeforeRendering(true);
>
> canvas.setClearColor(QColor(Qt::transparent));
>
> canvas.setWindowFlags(Qt::FramelessWindowHint);
Looks good, I'd expect this to give the expected outcome. Try the alpha
buffer fix, and if it still doesn't work please file a bug. It might be
that noone has tested this properly with Qt 5 yet.
> Would you please tell me something about how does Qt Quick2 render the
> scene? I think it doesn't render opengl into video memory
> directly because if so, when I drag one other window above the qml
> scene, it should flash :) So does it use QGLPixelBuffer class for that?
> I am new to opengl and scene graph, I am not clear with the work flow.
> But I really want to make the QML View Translucent, this will be very
> cool ^_^
It does render directly to the window (although potentially in a
separate thread), not sure what kind of flashing you expect, that's
mostly solved by compositing window managers.