[Solved]Using qpainter to create image



  • I am trying to create a css generator like the one here: "http://www.colorzilla.com/gradient-editor/":http://www.colorzilla.com/gradient-editor/ . The preview pane dynamically changes according to the options selected. I want to create something of that sort. I'm trying to use QPainter to draw QRects, but unable to apply gradients. And how to apply border radius to it? And finally, I should be able to convert the preview to an image. Please help me out.
    Thanks in advance!


  • Moderators

    this code draws a rounded rect (2px radius) filled with a gradient (linear from left to right) using QPainter:
    @
    QLinearGradient gradient(0, 0, 1, 0);
    gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
    gradient.setColorAt( 0, color1 );
    gradient.setColorAt( 1, color2 );

    QPainter p(..);
    p.setPen( ... ); //rect border
    p.setBrush( gradient );
    p.drawRoundedRect( rect, 2, 2 );
    @



  • Worked, thanks!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.