Skip to content

Instantly share code, notes, and snippets.

@ironhouzi
Created August 3, 2014 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironhouzi/909721619d3584f25136 to your computer and use it in GitHub Desktop.
Save ironhouzi/909721619d3584f25136 to your computer and use it in GitHub Desktop.
import sys
from PyQt4.QtGui import \
QApplication, \
QDialog, \
QGraphicsScene, \
QGraphicsView, \
QVBoxLayout, \
QPainter
from PyQt4.QtCore import \
QRectF, \
Qt
class GraphicsView(QGraphicsView):
def __init__(self, fname='', parent=None):
super(GraphicsView, self).__init__(parent)
self.setDragMode(QGraphicsView.RubberBandDrag)
self.setRenderHint(QPainter.Antialiasing)
self.setRenderHint(QPainter.TextAntialiasing)
def wheelEvent(self, event):
factor = 1.41 ** (-event.delta() / 240.0)
self.scale(factor, factor)
class Editor(QDialog):
def __init__(self, parent=None):
super(Editor, self).__init__(parent)
pageSize = (842, 198)
f = open('alotbsol.txt')
txt = f.read()
view = GraphicsView()
scene = QGraphicsScene(self)
scene.setSceneRect(0, 0, pageSize[0], pageSize[1])
rect = QRectF(0, 0, pageSize[0], pageSize[1])
scene.addRect(rect, Qt.black)
textbox = scene.addText(txt)
textbox.setTextWidth(pageSize[0])
view.setScene(scene)
layout = QVBoxLayout()
layout.addWidget(view, 1)
self.setLayout(layout)
self.resize(scene.width() + 50, scene.height() * 2)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = Editor()
widget.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment