[Development] How to set QQuickView TranslucentBackground

hailong geng longlongh4 at yahoo.com
Thu Mar 8 02:37:37 CET 2012


Hi
   What I have to say is that Qt5 is really cool, I love it ^_^
   But I get a problem, I want to show some lovely tools in desktop, in order to move them freely, I want to set the window Translucent and show the app in FullScreen mode(or in available screen geometry).  In Qt4 I can set Qt::WA_TranslucentBackground and it works well. Now I want use Qt5 to do that, but I can't find the way, I tried the following code and got only a grey background. I used the mine example to test and the code I have changed is marked in yellow.

#include<QtGui/QGuiApplication>
#include<QtQuick/qquickview.h>
#include<QtDeclarative/QDeclarativeContext>
#include<QtDeclarative/QDeclarativeEngine>
#include"minehunt.h"
intmain(intargc,char*argv[])
{
QGuiApplicationapp(argc,argv);
QQuickViewcanvas;
canvas.setWindowFlags(Qt::FramelessWindowHint);
qmlRegisterType<TileData>();
MinehuntGame*game=newMinehuntGame();
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();
returnapp.exec();
}

importQtQuick2.0
import"MinehuntCore"2.0
Item{
id:root
width:1920
height:1080
Item{
id:field
propertyintclickx:0
propertyintclicky:0
width:450;height:450
Image{source:"MinehuntCore/pics/background.png";anchors.fill:parent;fillMode:Image.Tile}
Grid{
anchors.horizontalCenter:parent.horizontalCenter
columns:9;spacing:1
Repeater{
id:repeater
model:tiles
delegate:Tile{}
}
}
Row{
id:gamedata
x:20;spacing:20
anchors.bottom:field.bottom;anchors.bottomMargin:15
Image{
source:"MinehuntCore/pics/quit.png"
scale:quitMouse.pressed?0.8:1.0
smooth:quitMouse.pressed
y:10
MouseArea{
id:quitMouse
anchors.fill:parent
anchors.margins:-20
onClicked:Qt.quit()
}
}
Column{
spacing:2
Image{source:"MinehuntCore/pics/bomb-color.png"}
Text{anchors.horizontalCenter:parent.horizontalCenter;color:"white";text:numMines}
}
Column{
spacing:2
Image{source:"MinehuntCore/pics/flag-color.png"}
Text{anchors.horizontalCenter:parent.horizontalCenter;color:"white";text:numFlags}
}
}
Image{
anchors.bottom:field.bottom;anchors.bottomMargin:15
anchors.right:field.right;anchors.rightMargin:20
source: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-20
horizontalAlignment:Text.AlignHCenter
wrapMode:Text.WordWrap
text:"Minehuntdemohastobecompiledtorun.\n\nPleaseseeREADME."
color:"white";font.bold:true;font.pixelSize:14
visible:tiles==undefined
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120307/80ab9c0f/attachment.html>


More information about the Development mailing list