PDA

View Full Version : Draw grid / Drop images onto grid / Turn grid into PNG



Poonarge
28th August 2014, 17:20
Hi,

I'm trying to make a program where you choose a texture, and size, and it will draw a grid. I've got this part working to an extent using QGraphicsScene & a GraphicsView.




void MainWindow::on_btnDrawGrid_clicked()
{
QGraphicsScene* scene = new QGraphicsScene;
ui->graphicsView->setScene(scene);

int height = ui->graphicsView->height();
int height2 = height / ui->txtGridX->text().toInt();
int length = ui->graphicsView->width();
int length2 = length / ui->txtGridY->text().toInt();

for (int x=0; x<=height; x+=height2)
scene->addLine(x,0,x,height, QPen(Qt::red));

for (int y=0; y<=length; y+=length2)
scene->addLine(0,y,length,y, QPen(Qt::red));

ui->graphicsView->fitInView(scene->itemsBoundingRect());
}


The next part is what I am stuck on. I want to drag and drop images onto the grid, move them around etc. Then, when I press save I need it to interpret the grid with images, and draw a PNG file with different colours representing the different bits of the grid, texture etc.

Any help and/or guidance would be much appreciated.

Regards,

Richard

Poonarge
4th September 2014, 09:09
Anyone any ideas?

anda_skoa
4th September 2014, 11:09
Implement the drag event handlers in a QGraphicsScene subclass and create QGraphicsPixmapItems or subclasses thereof for each dropped image.
For rendering the result see QGraphicsScene::render()

Cheers,
_