Using PyQt4.

My goal is to load in "parts" of a .png, assign them to QGraphicsItems, add them to the scene, and have the QGraphicsView display them. (Right now I don't care about their coordinates, all I care about is getting the darn thing to work).

Currently nothing is displayed. At first I thought it was a problem with items being added and QGraphicsView not updating, but after reading up a bit more on viewports, that didn't really make sense. So I tested adding the QGraphicsView items before even setting the view (so I know it wouldn't be an update problem) and it still displayed nothing. The path is definitely correct. Here is some code that shows what is going on...

Qt Code:
  1. class TileBar(QtGui.QGraphicsScene):
  2. def __init__(self, parent = None):
  3. QtGui.QGraphicsScene.__init__(self, parent)
  4.  
  5. def loadTiles(self, filename):
  6. tree = ElementTree()
  7. tree.parse(filename)
  8. root = tree.getroot()
  9.  
  10. sheets = root.findall('sheet')
  11.  
  12. for sheet in sheets:
  13. sheetPath = sheet.get('path')
  14. sheetImg = QtGui.QImage(sheetPath)
  15.  
  16. strips = sheet.findall('strip')
  17. for strip in strips:
  18. tile = Tile()
  19. tile.idAttr = strip.get('id')
  20.  
  21. clip = strip.find('clip')
  22. x = clip.get('x')
  23. y = clip.get('y')
  24. width = clip.get('width')
  25. height = clip.get('height')
  26.  
  27. subImg = sheetImg.copy(int(x), int(y), int(width), int(height))
  28. pixmap = QtGui.QPixmap.fromImage(subImg)
  29. tile.setPixmap(pixmap)
  30.  
  31. self.addItem(tile)
To copy to clipboard, switch view to plain text mode 

*Note that the Tile class is just a QGraphicsItem (inherits it) with an idAttr attribute. That is it.

and...

Qt Code:
  1. class MainWindow(QtGui.QMainWindow):
  2. def __init__(self, parent = None):
  3. QtGui.QMainWindow.__init__(self, parent)
  4.  
  5. self.setWindowTitle('NT State Editor')
  6.  
  7. winWidth = 1024
  8. winHeight = 768
  9.  
  10. screen = QtGui.QDesktopWidget().availableGeometry()
  11. screenCenterX = (screen.width() - winWidth) / 2
  12. screenCenterY = (screen.height() - winHeight) / 2
  13. self.setGeometry(screenCenterX, screenCenterY, winWidth, winHeight)
  14.  
  15. self.tileMap = tilemap.TileMap()
  16. self.tileBar = tilebar.TileBar()
  17.  
  18. mapView = QtGui.QGraphicsView(self.tileMap)
  19. tileBarView = QtGui.QGraphicsView(self.tileBar)
  20.  
  21. button = tilebar.LoadTilesButton()
  22. QtCore.QObject.connect(button, QtCore.SIGNAL('selectedFile'),
  23. self.tileBar.loadTiles)
  24.  
  25. hbox = QtGui.QHBoxLayout()
  26. hbox.addWidget(mapView)
  27. hbox.addWidget(self.tileBarView)
  28. hbox.addWidget(button)
  29.  
  30. mainWidget = QtGui.QWidget()
  31. mainWidget.setLayout(hbox)
  32.  
  33. self.setCentralWidget(mainWidget)
  34.  
  35.  
  36. app = QtGui.QApplication(sys.argv)
  37. mainWindow = MainWindow()
  38. mainWindow.show()
  39. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 

I tried some stuff with connecting the TileBar's 'changed()' signal with various 'view' functions, but none of them worked. I've had a bit of trouble finding good examples of ways to use the Graphics View Framework, (most are very very small scale) so let me know if I'm doing it completely wrong.

Any help is appreciated. Thanks.