Results 1 to 3 of 3

Thread: QGraphicsView

  1. #1
    Join Date
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QGraphicsView

    hi,

    I haven't been able to use QGraphicsView. I didn't understand the concept of QScene. Even i can't use QImage to display an image through QGraphicsView. What shoul i do? Plz guide!!

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView

    Quote Originally Posted by Yayati.Ekbote View Post
    hi,

    I haven't been able to use QGraphicsView. I didn't understand the concept of QScene. Even i can't use QImage to display an image through QGraphicsView. What shoul i do? Plz guide!!
    You can have a look, in Qt Docs regarding the basic of model view architecture. For now, Qt's MVA is rich set of classes helps you to create rich graphical applications. And this is efficient also, to give you good performance. There are 3 main classes in this MVA.
    1. The QGraphicsItem represents the item to be drawn/shown. It could be anything like a line, rect, ellipse, curve, image. So we need to use appropriate class for the customized usage.
    2. The QGraphiceScene is a canvas like background where all kind of graphics item resides. The scene has full control over all items. All kind of drawing happens on the scene.
    3. The QGraphicsView is a Qt widget, which acts like the parent for QGraphicsScene. This just provides the place where you can use scene. And if you can use scene, you can use items.

  3. The following user says thank you to yogeshgokul for this useful post:

    Yayati.Ekbote (5th March 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView

    The VGT I am working on is GPL and Open Source. While making the switch I have been able to rewrite portions of the old and dusty code so that portions of it could be lent to other softwares. Here is a link so you can download the full source: http://my.pogoplug.com/share/RPBBQftK2AaDIG99LwumcA/

    This is what I am doing. First .. I have ripped apart the UI and the calculations so the code you are going to see is just a widget that will be docked into the UI. Also, the code is in PyQt, but with some translation you should be able to see how it could fit in pure Qt.

    Qt Code:
    1. # Maintainer (Traipse): Tyler Starke
    2. # Version: Traipse 'Pious-Paladin'
    3. # $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
    4. #
    5. # Description: Base Map Gear
    6.  
    7. """
    8. Planned Implementation:
    9.  
    10. The map will change first and foremost by creating a new layer called the Table Layer. This layer will be just that, a table.
    11.  
    12. The Background layer will be a bit different
    13. """
    14.  
    15. from PyQt4 import QtGui, QtCore
    16. from tool_gears.path_gear import path
    17. from map_engine.scroll_gear import ScrollGear
    18. from map_engine.mini_gear import MiniGear
    19.  
    20. class MapDocket(QtGui.QGraphicsView):
    21.  
    22. def __init__(self):
    23. super(MapDocket, self).__init__()
    24. self.createDocket()
    25. self.createMap()
    26. self.setScene(self.mapView)
    27. self.centerOn(0,0)
    28. self.show()
    29.  
    30. def createDocket(self):
    31. self.setBackgroundBrush(QtGui.QBrush(QtGui.QPixmap(path['textures']+'versa_anigre.jpg')))
    32. self.setCacheMode(QtGui.QGraphicsView.CacheBackground)
    33. self.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate)
    34. self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
    35.  
    36. def createMap(self):
    37. self.mapView = QtGui.QGraphicsScene()
    38. #self.dropEvent = self.sceneDropEvent
    39. self.mapView.setSceneRect(0, 0, 1000, 1000)
    40. self.mapView.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
    41.  
    42. item = MiniGear(path['textures']+'grass-natural.jpg')
    43. self.mapView.addItem(item)
    44. item = MiniGear(path['textures']+'water20.jpg')
    45. self.mapView.addItem(item)
    46.  
    47. def dropEvent(self, evt):
    48. print 'Dropped'
    49.  
    50.  
    51. def wheelEvent(self, evt):
    52. scale = evt.delta()
    53. if scale < 0: x = .9; y = .9
    54. if scale > 0: x = 1.1; y = 1.1
    55. self.scale(x, y)
    To copy to clipboard, switch view to plain text mode 

    What I do is class a GraphicsView and then I create the scene in side and set the scene to the view. Then I can add items to the seen. See how I am adding items? Here is the class in its current state:

    Qt Code:
    1. # Version: Traipse 'Pious-Paladin'
    2. # $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
    3. #
    4. # Description: Base Map Gear
    5.  
    6. from PyQt4 import QtGui
    7. from tool_gears.path_gear import path
    8.  
    9. class MiniGear(QtGui.QGraphicsPixmapItem):
    10.  
    11. def __init__(self, pixmap):
    12. super(MiniGear, self).__init__()
    13. self.setPixmap(QtGui.QPixmap(pixmap))
    14. self.setAcceptDrops(True)
    15. self.setAcceptHoverEvents(True)
    16. self.setFlags(QtGui.QGraphicsItem.ItemIsMovable)
    17.  
    18. def dropEvent(self, evt):
    19. print 'Dropped'
    20.  
    21. def dragMoveEvent(self, evt):
    22. print 'Move'
    To copy to clipboard, switch view to plain text mode 

    I am creating items this way because it will give me a lot more options to manipulate the item later. If I create a dictionary of Map Minis, and I will, I can pull a stunt like this.

    Qt Code:
    1. image = MiniGear(path['textures']+'grass-natural.jpg')
    2. self.mapMinis[self.minis] = image
    3. self.minis += 1
    To copy to clipboard, switch view to plain text mode 

    This puts that image into the dictionary, but the image will also have callable functions, practically inside itself. So later I will be able to do something like

    Qt Code:
    1. self.mapMinis[0].addEffect( Effect )
    To copy to clipboard, switch view to plain text mode 

    And that item will have an effect added to it.

  5. The following user says thank you to prof.ebral for this useful post:

    Yayati.Ekbote (5th March 2010)

Similar Threads

  1. QGraphicsView
    By hgedek in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2007, 09:16
  2. QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2007, 08:00
  3. QGraphicsView
    By Shawn in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2007, 14:31
  4. help with QGraphicsView
    By Erlendhg in forum Qt Programming
    Replies: 6
    Last Post: 22nd April 2007, 20:26
  5. Regarding QGraphicsView
    By kiranraj in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2006, 04:59

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.