0

i have been able to draw only one rectangle but i need to draw 64 rectangles using a painter. so please can anyone help me..? i need 64 rectangles with different co_ordinates so plz help me how to change the coordinates . should i hardcode the x and y co-ordinates.

the code is as follows:

#include <QPaintEvent>
#include <QMainWindow>
void paintEvent(QPaintEvent *event)
{
  QRect rectangle(0,0,100,100);
  QPainter painter;
  painter.setBrush(Qt::black);
  painter.drawRext(rectangle);
}
Manualmsdos
  • 1,505
  • 3
  • 11
  • 22
  • https://stackoverflow.com/questions/15829192/can-someone-help-me-modify-this-code-im-trying-to-display-a-checkerboard-c-q maybe this could help? – Hafnernuss Nov 11 '19 at 07:39

1 Answers1

0
void paintEvent()
{
int x=0,y=0;
int temp=0;
QPainter painter;
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
   if(temp==0)
{
painter.setBrush(Qt::black);
temp++;
}
else
{
painter.setBrush(Qt::white);
temp--;
}
   QRect r(x,y,100,100);
   painter.drawRect(r);
   x+=100;
}
x=0;
y+=100;
if(temp==0)
temp=1;
else
 temp=0;
}
}