Results 1 to 3 of 3

Thread: Draw grid / Drop images onto grid / Turn grid into PNG

  1. #1
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Draw grid / Drop images onto grid / Turn grid into PNG

    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.


    Qt Code:
    1. void MainWindow::on_btnDrawGrid_clicked()
    2. {
    3. ui->graphicsView->setScene(scene);
    4.  
    5. int height = ui->graphicsView->height();
    6. int height2 = height / ui->txtGridX->text().toInt();
    7. int length = ui->graphicsView->width();
    8. int length2 = length / ui->txtGridY->text().toInt();
    9.  
    10. for (int x=0; x<=height; x+=height2)
    11. scene->addLine(x,0,x,height, QPen(Qt::red));
    12.  
    13. for (int y=0; y<=length; y+=length2)
    14. scene->addLine(0,y,length,y, QPen(Qt::red));
    15.  
    16. ui->graphicsView->fitInView(scene->itemsBoundingRect());
    17. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by Poonarge; 28th August 2014 at 17:30.

  2. #2
    Join Date
    Jun 2014
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Draw grid / Drop images onto grid / Turn grid into PNG

    Anyone any ideas?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Draw grid / Drop images onto grid / Turn grid into PNG

    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,
    _

Similar Threads

  1. How to add images to grid
    By vinayaka in forum Newbie
    Replies: 2
    Last Post: 28th July 2011, 06:21
  2. Draw grid in QListView
    By woodtluk in forum Qt Programming
    Replies: 2
    Last Post: 22nd September 2010, 13:54
  3. Cant't draw custom grid
    By Tottish in forum Qwt
    Replies: 4
    Last Post: 1st May 2010, 09:55
  4. Regarding placing images in the grid
    By prajna in forum Newbie
    Replies: 1
    Last Post: 20th February 2009, 08:01
  5. Drag and drop grid?
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 18:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.