Qt Quick2 window can't be transparent without

2019-06-04 07:49发布

I'm using Qt 5.7 on Windows 7.

I can make my QWindow have opacity, but it can't be transparent.

// window1.qml
Window {
    width: 640
    height: 480
    color: "transparent"
} // no transparent, black background


// window2.qml
Window {
    width: 640
    height: 480
    color: "transparent"
    opacity: 0.5
} // black but 50% opacity background

But if I enable aero, then it would be transparent without any problem.

I've read a lot of articles about it. but I couldn't find correct answer.

https://stackoverflow.com/a/22554797/6356562 - set surface format

This answer doesn't work for me.

How can I solve it?

标签: c++ qt qml
1条回答
够拽才男人
2楼-- · 2019-06-04 07:55

I tried this code with Qt 5.8:

Window {
  width: 200
  height: 200
  visible: true

  color: "transparent"
  opacity: 0.9

  Button {
    anchors.centerIn: parent
    text: "Click Me!"
  }
}

And I get this result: Transparent QtQuickControls2 I recommend you use Qt 5.8.

查看更多
登录 后发表回答