Results 1 to 4 of 4

Thread: GraphicsScene Background repainting

  1. #1
    Join Date
    May 2007
    Posts
    106
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60
    Thanked 3 Times in 3 Posts

    Angry GraphicsScene Background repainting

    Hi guys,

    I want to have a grid on my graphicsScene of customized size. I have a serious problem with GraphicsScene background drawing. I have implemented the drawBackground() function in my graphicsScene class as follows:

    Qt Code:
    1. painter->drawRect(rect);
    2. if(gridSize>0)
    3. {
    4. painter->setOpacity(0.1);
    5. for(int i=0;i<rect.width();i+=gridSize)
    6. painter->drawLine(i,0,i,rect.height());
    7. for(int i=0;i<rect.height();i+=gridSize)
    8. painter->drawLine(0,i,rect.width(),i);
    9. }
    To copy to clipboard, switch view to plain text mode 

    The grid is repainted every time I move, resize, rotate any item on the scene. And this repainting leaves some extra lines drawn on the scene?? It looks very ugly. Please help me as this is urgent!!

    Regards,
    Manoj
    Last edited by jpn; 18th December 2007 at 07:32. Reason: missing [code] tags

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    37
    Thanked 53 Times in 40 Posts

    Default Re: GraphicsScene Background repainting

    If rect you have used is the parameter passed in drawBackground(), then your code is wrong!
    That is because rect is the rectangle to be repainted and its size differs in each call
    For example try
    qDebug() << rect
    in drawBackground() and watch out the values.

    Have a look at this thread. It might be helpful
    http://qtcentre.org/forum/f-qt-progr...cene-5609.html
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #3
    Join Date
    May 2007
    Posts
    106
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60
    Thanked 3 Times in 3 Posts

    Default Re: GraphicsScene Background repainting

    I am sorry for the confusion as I just renamed some parameters in the code and then posted. The rect I am using here is the sceneRect. Any solution?

    Regards,
    Manoj

  4. #4
    Join Date
    May 2007
    Posts
    106
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60
    Thanked 3 Times in 3 Posts

    Default Re: GraphicsScene Background repainting

    Thanks Gopala. The thread you reffered has proven a great help for me. Now I am just using the view's cacheBackground flag and it is working perfectly fine for me.
    Initially I created a seperate item class to draw the Grid, but this option is a better one. :-)

Similar Threads

  1. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  2. Replies: 1
    Last Post: 5th April 2006, 16:44

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
  •  
Qt is a trademark of The Qt Company.