我的需求是在一个QQuickWindow上展示一个QWidget控件,需要将这个QWidget的背景设置为透明,但是现在如果设置QWidget的Qt::WA_TranslucentBackground属性,背景就变成黑的,请问有什么解决办法?
代码如下:
QQuickView *viewer;
viewer = new QQuickView(QUrl::fromLocalFile("main.qml"));
viewer->setResizeMode(QQuickView::SizeRootObjectToView);
viewer->setFlags(Qt::Window|Qt::FramelessWindowHint);
viewer->setGeometry(150,150,400,400);
viewer->show();
QWidget *widget=new QWidget;
widget->setAttribute(Qt::WA_NativeWindow,true);
widget->setAutoFillBackground(false);
widget->setWindowFlags(Qt::FramelessWindowHint);
widget->setGeometry(120,120,350,350);
widget->windowHandle()->create();
widget->windowHandle()->setParent(viewer);
widget->setAttribute(Qt::WA_TranslucentBackground,true);
widget->show();
QPushButton *btn=new QPushButton(widget);
btn->setGeometry(20,20,50,50);
btn->setText("1231231");
btn->show();