void line::paintEvent(QPaintEvent *c)
{
//lines
QPainter line(this);
line.setRenderHint(QPainter::Antialiasing,true);
line.setPen(QPen(Qt::black,2,Qt::SolidLine,Qt::RoundCap,Qt::MiterJoin));
line.setBrush(QBrush(Qt::black,Qt::SolidPattern));
line.drawLine(50,50,50,200); // Y axis
line.drawLine(50,200,250,200); // x axis
// rectangle
int a[5] ={20,60,120,30,200}; //length = a[]
int x= 50.0 ;
int y= 200 ;
for(int i=0 ; i<5 ;i++)
{
int inc = 200/5;
for(int j=0 ; j<200 ;j=j+inc)
{
QRectF rect((x+j),(y-a[i]),0.0,a[i]);
line.setPen(QPen(Qt::green,8,Qt::SolidLine,Qt::RoundCap,Qt::MiterJoin));
line.drawRect(rect);
}
}
}
|