Results 1 to 5 of 5

Thread: Scene.DrawBackgrount: want to know dimensions of view window

  1. #1
    Join Date
    Apr 2010
    Posts
    16
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Scene.DrawBackgrount: want to know dimensions of view window

    I have a MyScene derived from QGraphicsScene where I implement a drawBackground. I now paint the sceneRect() with a grid. But I would like to extend painting the grid to the outside area if the sceneRect is smaller than the view window. How do I get these dimensions?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Scene.DrawBackgrount: want to know dimensions of view window

    Quote Originally Posted by lightning2911 View Post
    But I would like to extend painting the grid to the outside area if the sceneRect is smaller than the view window.
    I read that 10 times, but I still do not get it.
    Can you explain this a little bit better?

    What is an outside area?
    What is a sceneRect?
    What is a view window?

  3. #3
    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: Scene.DrawBackgrount: want to know dimensions of view window

    Better use QGraphicsView::drawBackground instead of the scene background

  4. #4
    Join Date
    Apr 2010
    Posts
    16
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Re: Scene.DrawBackgrount: want to know dimensions of view window

    I read that 10 times, but I still do not get it.
    Can you explain this a little bit better?
    I will try with an image or two:



    This is a scene where the sceneRect() is painted gray and dots are painted on grid position. The sceneRect is centered in the window.

    How do I know the dimensions of the white space around so that I can fill this space also with grid dots (or whatever)? I want to achieve this:


    For this screen i have just added a fixed amount to the screenRect but I would like to know what the dimensions of that space around the sceneRect really are.

    This is what the code looks like.

    Qt Code:
    1. class MyScene(QGraphicsScene):
    2.  
    3. def __init__(self, parent=None):
    4. super(MyScene, self).__init__(parent)
    5. self.pen = QPen(Qt.black, 1, Qt.SolidLine)
    6. self.brush = QBrush(Qt.gray, Qt.SolidPattern)
    7. self.gridSize = SCREEN_GRID_SIZE
    8. self.gridX = SCREEN_GRID_X
    9. self.gridY = SCREEN_GRID_Y
    10. self.setSceneRect(- self.gridSize * self.gridX / 2, - self.gridSize * self.gridY / 2, self.gridSize * self.gridX, self.gridSize * self.gridY)
    11.  
    12. def drawBackground(self, painter, rect):
    13. # draw a rect in size of sceneRect
    14.  
    15. # draw frame
    16. painter.setPen(QPen(Qt.red, 0, Qt.NoPen))
    17. painter.setBrush(QBrush(Qt.lightGray, Qt.SolidPattern))
    18. painter.drawRect(self.sceneRect())
    19.  
    20. # draw grid
    21. painter.setBrush(QBrush(Qt.darkGray, Qt.SolidPattern))
    22. print self.sceneRect()
    23. for y in range(int(self.sceneRect().y()), int(self.sceneRect().y())+int(self.sceneRect().height()+1), self.gridSize):
    24. for x in range(int(self.sceneRect().x()), int(self.sceneRect().x())+int(self.sceneRect().width()+1), self.gridSize):
    25. # change color for center point
    26. if x == 0 and y == 0:
    27. painter.save()
    28. painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))
    29. # draw a point
    30. painter.drawRect(x-1, y-1, 2, 2)
    31. # change color back if center point
    32. if x == 0 and y == 0:
    33. painter.restore()
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2010
    Posts
    16
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Re: Scene.DrawBackgrount: want to know dimensions of view window

    thanks aamer4yu, i did not see that the view also had a drawbackground method. got it working now.

Similar Threads

  1. QGraphicsItem .. Scene .. View question?
    By DirtyBrush in forum Qt Programming
    Replies: 21
    Last Post: 19th October 2010, 09:12
  2. View,Scene and RectItem
    By salmanmanekia in forum Newbie
    Replies: 2
    Last Post: 29th March 2010, 14:31
  3. View, Scene, Item and thread??
    By dungsivn in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 19:21
  4. how to zoom out item in View/Scene
    By nileshsince1980 in forum Qt Programming
    Replies: 7
    Last Post: 28th December 2007, 10:24
  5. Scrolling problem with background using View/Scene
    By nileshsince1980 in forum Qt Programming
    Replies: 5
    Last Post: 22nd October 2007, 08:19

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.