Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <strong>setAttribute( Qt.WA_TranslucentBackground, True)</strong> method shown <strong><a href="https://stackoverflow.com/questions/1909092/qt4-transparent-window-with-rounded-corners">here</a></strong> also works... Simply set this attribute on your top-level window, and paint the shape of your window using a QPainterPath in a <strong>paintEvent()</strong> method override.</p> <p>Here's some <strong><em>(python)</em></strong> code that might help you construct, or paint, the QPainterPath for a rectangle with rounded corners.</p> <pre><code>def drawPartiallyRoundedRect(painter,x,y,w,h, radiusTR, radiusBR, radiusBL, radiusTL, doFill,fillColor, doLine=False,lineColor=None,lineWidth=1, antiAlias=True): w2 = int(w/2.0) h2 = int(h/2.0) if (doLine): x += lineWidth/2.0 y += lineWidth/2.0 w -= lineWidth h -= lineWidth T = y L = x R = x + w B = y + h # clamp values to fit within rect if (radiusTR &gt; w2): radiusTR = w2 if (radiusTR &gt; h2): radiusTR = h2 if (radiusTL &gt; w2): radiusTL = w2 if (radiusTL &gt; h2): radiusTL = h2 if (radiusBL &gt; w2): radiusBL = w2 if (radiusBL &gt; h2): radiusBL = h2 if (radiusBR &gt; w2): radiusBR = w2 if (radiusBR &gt; h2): radiusBR = h2 diamTR = radiusTR + radiusTR diamBR = radiusBR + radiusBR diamBL = radiusBL + radiusBL diamTL = radiusTL + radiusTL p = QPainterPath() if (radiusTR &gt; 0.0): p.moveTo(R, T + radiusTR); p.arcTo(R-diamTR, T, diamTR, diamTR, 0.0, 90.0) # TR else: p.moveTo(R,T) if (radiusTL &gt; 0.0): p.arcTo(L, T, diamTL, diamTL, 90.0, 90.0) # TL else: p.lineTo(L,T) if (radiusBL &gt; 0.0): p.arcTo(L, B-diamBL, diamBL, diamBL, 180.0, 90.0); # BL else: p.lineTo(L,B) if (radiusBR &gt; 0.0): p.arcTo(R-diamBR, B-diamBR, diamBR, diamBR, 270.0, 90.0); # BR else: p.lineTo(R,B) p.closeSubpath(); if (antiAlias): painter.setRenderHint(QPainter.Antialiasing,True) else: painter.setRenderHint(QPainter.Antialiasing,False) if (doFill and fillColor): painter.setBrush( fillColor ) elif ( doFill ): # pass doFill and None for fillColor to use current brush pass else: painter.setBrush( Qt.NoBrush ) if ((lineWidth != 0.0) and doLine and lineColor): pen = QPen( lineColor, lineWidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin ) painter.setPen( pen ) else: painter.setPen( Qt.NoPen ) painter.drawPath( p ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload