#include class MyWidget : public QWidget { public: MyWidget(QWidget *parent = 0) : QWidget(parent) {} protected: void paintEvent(QPaintEvent *) { QPixmap p("test.png"); QPainter paint(this); paint.drawPixmap(0,0,p); } }; class MyOverlayWidget : public QWidget { public: MyOverlayWidget(QWidget *parent = 0) : QWidget(parent, Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus | Qt::NoDropShadowWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint // Note, this is necessary on Linux. Without this flag, the manual widget resize() doesn’t seem to take effect. Removing this flag, however, does not fix the transparent rendering issue. | Qt::Tool) { setAttribute(Qt::WA_TranslucentBackground); } protected: void paintEvent(QPaintEvent *) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setCompositionMode(QPainter::CompositionMode_Clear); painter.fillRect(rect(), Qt::red); // technically any color would work painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawRect(QRect(10,10,200,200)); } }; int main(int argc, char **argv) { QApplication::setAttribute(Qt::AA_ImmediateWidgetCreation); QApplication a(argc, argv); MyWidget w; w.show(); MyOverlayWidget overlay; overlay.setGeometry(w.geometry()); overlay.show(); return a.exec(); }