C++/QT, window top causes transparent background can not be set
The bottom window of this window is the set transparent window, and the main layout is superimposed. The normal startup display is normal, including no border, transparent background and shadow. Now add a window top button, the user can click this button to lock the window top and unlock the window top. The modern code is as follows: when the user clicks, the window is normally placed at the top or unplaced at the top, but the background becomes black, even if the background transparency setting code is added, it will not help! < br / > as for the normal operation: < br / >
< div class = "aw - list - img >
void CodeBook::on_setTopHint() {
if (!isWidTop) {
QWindow* pWin = this->windowHandle();
pWin->setFlags(Qt::Widget | Qt::WindowStaysOnTopHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
cbWid->setBtnLockState(true);
qDebug() << u8"CodeBook001: 切换窗口为最顶层";
}else {
QWindow* pWin = this->windowHandle();
pWin->setFlags(Qt::Widget);
this->setAttribute(Qt::WA_TranslucentBackground, true);
cbWid->setBtnLockState(false);
this->show();
qDebug() << u8"CodeBook001: 取消窗口为最顶层";
}
isWidTop = !isWidTop;
}
As shown in the figure, after clicking the top button, the window is placed on top but the background is no longer transparent:
tried to solve with the following code, but did not achieve the desired effect:
this->setWindowFlags(Qt::WindowStaysOnTopHint);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
this->show();
0 Answer
No answer yet
这家伙很懒,什么都没留下...