Created
August 3, 2014 11:26
-
-
Save ironhouzi/909721619d3584f25136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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