I am using Qt5 to create an Windows application. I develop the complex user interface using QWebEngineView. The UI needs a transparent background. So I made the following settings:
this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setAutoFillBackground(true);
this->setWindowFlags(Qt.FramelessWindowHint);
...
this->web = new QWebEngineView(this);
this->web->setAttribute(Qt::WA_TranslucentBackground);
this->web->setStyleSheet("background:transparent");
this->web->page()->setBackgroundColor(Qt::Transparent);
this->web->load(QUrl::fromLocalFile(htmlpath));
And in the css file, I set:
html,body {
background: transparent;
}
The page shows to be transparent as I can see out the wallpaper through the page.
But I want to embed the widget into the desktop (that means it won't block other windows, and won't be minimized even when user press Win+D to show the desktop). So I utilizes Windows APIs:
HWND hDesktop = FindWindow("Progman", NULL);
SetParent(this->winId(), hDesktop);
The widget is embedded into the desktop now. But I found that the web page background is not transparent anymore, instead it is laid on a black background. Is there any idea on why and how to solve this problem?
I also tried to set the page background color with a self-made QColor whose alpha value is 0:
this->web->page()->setBackgroundColor(QColor(255,255,255,0));
And the page background changed to white with no transparency. So it seems that in this case the QWebEnginePage just ignores the alpha channel but adopts the R&G&B channels of the background color.
Environment:
- Windows 10 - Version 1803 (17134.407)
- Qt 5.11.2
I tested my program on another computer recently. However, the transparency is effective on the latter computer. The OS version and Qt version are both same with the former computer. I don't know what difference makes up the problem now.
Comments
Post a Comment