Search code examples
qtqpainter

Drawing a line on transparent qt widget


I want to achieve this :

  1. Have a transparent surface of some width and height (A transparent widget)
  2. Draw something on this surface such that only outlines of that figure are visible on the screen and nothing else (no background of the surface on which I am drawing should be there)

I made a widget and achieved to make it transparent like this :

window.setAttribute( Qt::WA_TranslucentBackground);
window.setWindowFlags (Qt::FramelessWindowHint);
window.setGeometry( 0,0,1200, 800 );
window.show();

Then I overrode the function paintEvent(QPaintEvent *); to make a ellipse using QPainter.

But still the surface is coming to be black color only. Can someone explain ?


Solution

  • Looks similar to what I did in a similar app, but I also did:

    window.setAutoFillBackground(false);
    

    Perhaps that's the missing piece for you?

    Edit: Another idea: In your paintEvent, do you fill the widget rect() with a fully transparent color before you paint the ellipse?