1
我有我可以「畫」一個數字的棋盤。QT如何保存到文件QPoint 2d陣列
這是名單板
void PrintRectangle::paintEvent(QPaintEvent *)
{
for(int i=0; i<5; i++)
{
ypos=20;
for(int j=0; j<5; j++)
{
QColor color = Qt::white;
for(int k=0; k<points.size(); k++){
if(i == points[k].x() && j == points[k].y())
{
color = Qt::black;
}
}
p.fillRect(xpos,ypos,recWidth,recHeight,color);
ypos+=60;
}
xpos+=60;
}
}
而接下來的功能,有哪些更新的點的代碼
QVector<QPoint> points;
void PrintRectangle::updateIndexFromPoint(const QPoint &point)
{
int x = point.x() - 20;
int y = point.y() - 20;
bool removed = false;
if(((x >= 0) && (x <= 300)) && ((y >= 0) && (y <= 300)))
{
mXIndex = x/60; //rec width + spacing
mYIndex = y/60; //rec height + spacing
for(int k=0; k<points.size(); k++){
qDebug("%d %d", points[k].x(), points[k].y());
if(points[k].x() == mXIndex && points[k].y() == mYIndex){
points.remove(k);
removed = true;
}
}
if(!removed){
points.append(QPoint(mXIndex,mYIndex));
}
}
}
我的問題是我怎麼能保存到文件NUMER從QPoint選擇長方形。
例如。在文件
0 0 1 0 0
0 1 1 0 0
1 0 1 0 0
0 0 1 0 0
0 0 1 0 0
'的std :: fstream'? –
我但是如何識別'Q''迭代'0'和'1'? – lukassz
你可以畫出來,當然你知道哪個是'0'和'1',不是嗎? –