Results 1 to 3 of 3

Thread: drawing a grid

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question drawing a grid

    how can i draw a grid of points on a widget of type QgraphicsView?

    I reimplement the PaintEvent method in my custom QgraphicsView class, but i can't see the points i draw......

    A simple line drawing i have implemented:
    Qt Code:
    1. void myview::paintEvent(QPaintEvent* event){
    2. qreal x,y,w,h;
    3. myscene->sceneRect().getRect(&x,&y,&w,&h);
    4.  
    5. QPainter painter(this);
    6. painter.setPen(Qt::black);
    7. painter.drawLine(x,y,w/2,h/2);
    8.  
    9. QGraphicsView::paintEvent(event);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by dreamer; 26th April 2008 at 20:06.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drawing a grid

    re implement the drawBackground() method of scene class.

    also in ur code above, u were just drawing a line. not points i guess. check ur code again what it does

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: drawing a grid

    It was just an example.......
    however, i resolve the problem reimplementing drawbackground() and drawforeground() in my custom QGraphicsScene class...

    thx

Similar Threads

  1. Snap-to grid on QGraphicsItem
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 28th April 2008, 17:22
  2. "Lay Out in a Grid" - how to see the grid?
    By will49 in forum Qt Tools
    Replies: 1
    Last Post: 25th July 2007, 21:09
  3. How to fill the blocks of the Grid one by one?
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2007, 13:20
  4. Grid Problem
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2007, 11:40
  5. Drawing on QWidget - strech & resize
    By kemp in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2007, 15:39

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.