简体   繁体   English

如何使用Qpainter在Qt中绘制棋盘

[英]How to draw chess board in Qt using Qpainter

i have been able to draw only one rectangle but i need to draw 64 rectangles using a painter.我只能绘制一个矩形,但我需要使用画家绘制 64 个矩形。 so please can anyone help me..?所以请任何人都可以帮助我..? i need 64 rectangles with different co_ordinates so plz help me how to change the coordinates.我需要 64 个具有不同坐标的矩形,所以请帮助我如何更改坐标。 should i hardcode the x and y co-ordinates.我应该对 x 和 y 坐标进行硬编码吗?

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);
}
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;
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM