I am new to Qt and was exploring demos of Qt.
I was trying the 40000 chip demo code and faced some confusion
1) I want to know the significance of choosing -11000 to 11000 in the function void MainWindow::populateScene()
2) if i change the loop, the chip movemment gets slow
The loop in void MainWindow::populateScene() function is
for (int i = -11000; i < 11000; i += 110) {
++xx;
int yy = 0;
for (int j = -7000; j < 7000; j += 70) {
++yy;
qreal x = (i + 11000) / 22000.0;
qreal y = (j + 7000) / 14000.0;
QColor color
(image.
pixel(int(image.
width() * x
),
int(image.
height() * y
)));
scene->addItem(item);
++nitems;
}
}
for (int i = -11000; i < 11000; i += 110) {
++xx;
int yy = 0;
for (int j = -7000; j < 7000; j += 70) {
++yy;
qreal x = (i + 11000) / 22000.0;
qreal y = (j + 7000) / 14000.0;
QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
QGraphicsItem *item = new Chip(color, xx, yy);
item->setPos(QPointF(i, j));
scene->addItem(item);
++nitems;
}
}
To copy to clipboard, switch view to plain text mode
If i replace the loop with
for (int i = 0; i < 22000; i += 110) {
++xx;
int yy = 0;
for (int j = 0; j < 14000; j += 70) {
++yy;
qreal x = (i) / 22000.0;
qreal y = (j) / 14000.0;
int w,h;
w= image.width();
h= image.height();
QColor color
(image.
pixel(int(image.
width() * x
),
int(image.
height() * y
)));
scene->addItem(item);
++nitems;
}
}
for (int i = 0; i < 22000; i += 110) {
++xx;
int yy = 0;
for (int j = 0; j < 14000; j += 70) {
++yy;
qreal x = (i) / 22000.0;
qreal y = (j) / 14000.0;
int w,h;
w= image.width();
h= image.height();
QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
QGraphicsItem *item = new Chip(color, xx, yy);
item->setPos(QPointF(i, j));
scene->addItem(item);
++nitems;
}
}
To copy to clipboard, switch view to plain text mode
and move the chips in the view, the movement is much slow.
What am i missing here ???
Bookmarks