#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: User
#
# Created: 20/02/2011
# Copyright: (c) User 2011
# Licence: <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui
def setupUi(self, ui):
ui.resize(600, 400)
self.
centralwidget = QtGui.
QWidget(ui
) self.
horizontalLayout = QtGui.
QHBoxLayout(self.
centralwidget) self.horizontalLayout.setContentsMargins(20, 20, 20, 20)
self.horizontalLayout.addWidget(self.graphicsView)
ui.setCentralWidget(self.centralwidget)
self.
graphicsView.
setGeometry(QtCore.
QRect(0,
0,
1000,
300)) self.graphicsView.setScene(self.graphicscene)
self.graphicsView.centerOn(0,0)
resize()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Escape:
self.close()
def resize():
print "im resizing" # iv tried all sorts here , what am i not seeing ?
def draw():
bru
=QtGui.
QBrush(QtCore.
Qt.
SolidPattern) bru.
setColor(QtGui.
QColor(255,000,000
)) pen.
setColor(QtGui.
QColor(255,
255,000
)) pen.setWidth(5)
font
=QtGui.
QFont('White Rabbit',
16) 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.') dot1.setFont(font)
dot1.setPos(5,5)
ui.graphicscene.addItem(dot1)
for x in range(10):
ui.graphicscene.addRect(20+(x*100),200,50,80,pen,bru)
ui.
graphicscene.
addRect(0,
0,
999,
300,QtGui.
QPen(QtGui.
QColor(000,000,
255),
5,QtCore.
Qt.
DashLine)) why
=QtGui.
QGraphicsTextItem("and why are these gaps here (top and bottom) when first run ?") why.
setFont(QtGui.
QFont('White Rabbit',
15)) why.setPos(400,-30)
ui.graphicscene.addItem(why)
if __name__ == '__main__':
ui = Ui_MainWindow()
ui.setupUi(ui)
ui.show()
draw()
sys.exit(app.exec_())
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: User
#
# Created: 20/02/2011
# Copyright: (c) User 2011
# Licence: <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):
def setupUi(self, ui):
ui.resize(600, 400)
self.centralwidget = QtGui.QWidget(ui)
self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
self.horizontalLayout.setContentsMargins(20, 20, 20, 20)
self.graphicsView = QtGui.QGraphicsView(self.centralwidget)
self.horizontalLayout.addWidget(self.graphicsView)
ui.setCentralWidget(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(0, 0, 1000, 300))
self.graphicscene=QtGui.QGraphicsScene(0,0,1000,300)
self.graphicsView.setScene(self.graphicscene)
self.graphicsView.centerOn(0,0)
def resizeEvent (self, QResizeEvent):
resize()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Escape:
self.close()
def resize():
print "im resizing" # iv tried all sorts here , what am i not seeing ?
def draw():
bru=QtGui.QBrush(QtCore.Qt.SolidPattern)
bru.setColor(QtGui.QColor(255,000,000))
pen=QtGui.QPen()
pen.setColor(QtGui.QColor(255,255,000))
pen.setWidth(5)
font=QtGui.QFont('White Rabbit',16)
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.')
dot1.setFont(font)
dot1.setPos(5,5)
ui.graphicscene.addItem(dot1)
for x in range(10):
ui.graphicscene.addRect(20+(x*100),200,50,80,pen,bru)
ui.graphicscene.addRect(0,0,999,300,QtGui.QPen(QtGui.QColor(000,000,255),5,QtCore.Qt.DashLine))
why=QtGui.QGraphicsTextItem("and why are these gaps here (top and bottom) when first run ?")
why.setFont(QtGui.QFont('White Rabbit',15))
why.setPos(400,-30)
ui.graphicscene.addItem(why)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ui = Ui_MainWindow()
ui.setupUi(ui)
ui.show()
draw()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks