well iv tried everything my small amount of Qt4 knowledge will stretch to including the suggestion above but i just cant get this working.

Iv made a proper demo so people can easily have a look.

Qt Code:
  1. #-------------------------------------------------------------------------------
  2. # Name: module1
  3. # Purpose:
  4. #
  5. # Author: User
  6. #
  7. # Created: 20/02/2011
  8. # Copyright: (c) User 2011
  9. # Licence: <your licence>
  10. #-------------------------------------------------------------------------------
  11. #!/usr/bin/env python
  12. import sys
  13. from PyQt4 import QtCore, QtGui
  14.  
  15. class Ui_MainWindow(QtGui.QMainWindow):
  16. def setupUi(self, ui):
  17. ui.resize(600, 400)
  18. self.centralwidget = QtGui.QWidget(ui)
  19. self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
  20. self.horizontalLayout.setContentsMargins(20, 20, 20, 20)
  21. self.graphicsView = QtGui.QGraphicsView(self.centralwidget)
  22. self.horizontalLayout.addWidget(self.graphicsView)
  23. ui.setCentralWidget(self.centralwidget)
  24. self.graphicsView.setGeometry(QtCore.QRect(0, 0, 1000, 300))
  25. self.graphicscene=QtGui.QGraphicsScene(0,0,1000,300)
  26. self.graphicsView.setScene(self.graphicscene)
  27. self.graphicsView.centerOn(0,0)
  28. def resizeEvent (self, QResizeEvent):
  29. resize()
  30.  
  31. def keyPressEvent(self, event):
  32. if event.key() == QtCore.Qt.Key_Escape:
  33. self.close()
  34.  
  35. def resize():
  36. print "im resizing" # iv tried all sorts here , what am i not seeing ?
  37.  
  38. def draw():
  39. bru=QtGui.QBrush(QtCore.Qt.SolidPattern)
  40. bru.setColor(QtGui.QColor(255,000,000))
  41. pen=QtGui.QPen()
  42. pen.setColor(QtGui.QColor(255,255,000))
  43. pen.setWidth(5)
  44. font=QtGui.QFont('White Rabbit',16)
  45. dot1=QtGui.QGraphicsTextItem('Graph goes here.\n\nWhat im trying to get is :-\n\nscrolls along X axis with scroll bar, no resizing,\nResizes to fit graphicsView along Y axis.')
  46. dot1.setFont(font)
  47. dot1.setPos(5,5)
  48. ui.graphicscene.addItem(dot1)
  49. for x in range(10):
  50. ui.graphicscene.addRect(20+(x*100),200,50,80,pen,bru)
  51. ui.graphicscene.addRect(0,0,999,300,QtGui.QPen(QtGui.QColor(000,000,255),5,QtCore.Qt.DashLine))
  52. why=QtGui.QGraphicsTextItem("and why are these gaps here (top and bottom) when first run ?")
  53. why.setFont(QtGui.QFont('White Rabbit',15))
  54. why.setPos(400,-30)
  55. ui.graphicscene.addItem(why)
  56.  
  57. if __name__ == '__main__':
  58. app = QtGui.QApplication(sys.argv)
  59. ui = Ui_MainWindow()
  60. ui.setupUi(ui)
  61. ui.show()
  62. draw()
  63. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 

When the window is resized I need the scene to remain 1:1 ratio on the X axis, it can be scrolled (this part works fine atm) & i need the Y axis to be resised to always fit in the graphicsView.


Any help is gratefully appreciated.