4

I've already know how to make a transparent window with Qt Quick 1.0.But I started to use Qt 5.0 and Qt Quick 2.0 recently and didn't know how to do with it.

setAttribute setWindowFlags setStyleSheet

The functions above are removed from the QtQuick2ApplicationViewer(QQuickView). So I wonder whether I can make a transparent window with Qt Quick 2 or not (is it because that it's based on OpenGL?).

animuson
  • 53,861
  • 28
  • 137
  • 147
Hongxu Xu
  • 63
  • 1
  • 7

2 Answers2

4

Here's a Qt5 code:

QSurfaceFormat surfaceFormat;
surfaceFormat.setAlphaBufferSize(8);
viewer.setFormat(surfaceFormat);
viewer.setClearBeforeRendering(true);
viewer.setColor(QColor(Qt::transparent));
Oleg Shparber
  • 2,732
  • 1
  • 18
  • 19
  • It works well! Thanks. In addition,I used 'viewer.setFlags(Qt::CustomizeWindowHint);'to hide the caption bar. But when I clicked the transparent area,it still responded to the event.How to deal with it? – Hongxu Xu Dec 31 '12 at 12:33
  • @XuHongxu see http://stackoverflow.com/a/4930925/721710 for a Windows solution... – Oleg Shparber Jan 08 '13 at 21:20
  • @andrewrjones - please check again, this solution worked for me on OSX 10.9.1, Qt 5.1.1. This should be marked as the correct solution. – aaronsnoswell Mar 03 '14 at 23:27
1

Look here for a possible solution:

http://code.google.com/p/quickwidget/

But, with Qt 5.3, it is possible to use the built-in QQuickWidget class.

user1095108
  • 14,119
  • 9
  • 58
  • 116