阅读本讨论后:Draw on top of xoverlay using Qt我最终得到了这段代码:
class Player : public QGst::Ui::VideoWidget { ... }
void Player::play() {
QGst::PipelinePtr pipeline = QGst::ElementFactory::make("playbin2").dynamicCast<QGst::Pipeline>();
watchPipeline(pipeline);
pipeline->setProperty("uri", "/path/to/my/video.mp4");
QGst::BusPtr bus = pipeline->bus();
bus->addSignalWatch();
QGlib::connect(bus, "message", this, &Player::onBusMessage);
pipeline->setState(QGst::StatePlaying);
}
所以我在这个QWidget
中播放了我的视频。现在,我想在此顶部添加另一个QWidget
来绘制内容或使用Alpha混合放置另一个QWidget
。我在主应用程序中尝试了这段代码:
Player *player = new Player(this);
QWidget *videoOverlay = new QWidget(player);
// set the videoOverlay geometry
videoOverlay->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
videoOverlay->setAttribute(Qt::WA_TranslucentBackground);
但是我得到了一个黑色的不透明QWidget
。完全没有透明度。
我错过了什么?
答案 0 :(得分:0)
试试这些:
videoOverlay->setAttribute(Qt::WA_NoBackground);
videoOverlay->setAttribute(Qt::WA_NoSystemBackground);
videoOverlay->setAutoFillbackground(false);
或者这个:
videoOverlay->setAutoFillBackground(true);
videoOverlay->setAttribute(Qt::WA_PaintOnScreen);
videoOverlay->setBackgroundRole(QPalette::Window);
// make the widget transparent
QPalette transparent;
transparent.setColor(QPalette::Window, QColor(128,64,128)); // transparent color
videoOverlay->setPalette(transparent);
第三种选择:
videoOverlay->setAttribute(Qt::WA_TranslucentBackground);
videoOverlay->setStyleSheet("background:transparent;");
有关如何使窗口小部件透明的更多信息: