0

After reading this discussion: Draw on top of xoverlay using Qt I've ended up with this code:

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);
}

So I have my video playing in this QWidget. Now I want to add another QWidget on top of this one to draw something or to place another QWidget with alpha blending. I tried this code in the main app:

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);

But I get a black opaque QWidget. There is no transparency at all. What am I missing?

Community
  • 1
  • 1
Mark
  • 4,338
  • 7
  • 58
  • 120

1 Answers1

0

Try these:

videoOverlay->setAttribute(Qt::WA_NoBackground);
videoOverlay->setAttribute(Qt::WA_NoSystemBackground);
videoOverlay->setAutoFillbackground(false);

Or this:

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);

Third option:

videoOverlay->setAttribute(Qt::WA_TranslucentBackground);
videoOverlay->setStyleSheet("background:transparent;");

More information about how to make widgets transparent:

user2448027
  • 1,628
  • 10
  • 11
  • This - like my code - works until I issue the watchPipeline(pipeline); on the target QWidget. After that the videoOverlay QWidget looses the transparency features. – Mark Jun 08 '13 at 11:51
  • @Mark Edited my answer. Also, can you set the attributes after issuing `watchPipeline(pipeline)`? – user2448027 Jun 08 '13 at 12:06
  • I'm very sorry but none of those works. If I set the parameter before the watchPipeline I have some transparency which will be lost just after the function. Setting them after issuing watchPipeline has no effect. Here the code of videoWidget.cpp (which contains that function) [link](http://gstreamer.freedesktop.org/data/doc/gstreamer/head/qt-gstreamer/html/videowidget_8cpp_source.html) – Mark Jun 08 '13 at 12:15