我需要创建一个alpha透明的小部件,它基本上是一个带有阴影的导航栏,并且下面的小部件需要通过阴影部分可见。该小部件加载PNG文件,然后在绘制事件中将其绘制出来。问题是阴影全部是黑色且不透明。
这是我目前正在使用的代码:
有人知道我需要改变什么来确保小部件真正透明吗?
这是我目前正在使用的代码:
NavigationBar::NavigationBar(QWidget *parent) : XQWidget(parent) {
backgroundPixmap_ = new QPixmap();
backgroundPixmap_->load(FilePaths::skinFile("NavigationBarBackground.png"), "png");
setAttribute(Qt::WA_NoBackground, true); // This is supposed to remove the background but there's still a (black) background
}
void NavigationBar::paintEvent(QPaintEvent* event) {
QWidget::paintEvent(event);
QPainter painter(this);
int x = 0;
while (x < width()) {
painter.drawPixmap(x, 0, backgroundPixmap_->width(), backgroundPixmap_->height(), *backgroundPixmap_);
x += backgroundPixmap_->width();
}
}
有人知道我需要改变什么来确保小部件真正透明吗?