主にページのレイアウトとドキュメントのページ付けに焦点を当てて、WYSIWYGワードプロセッサを作成するためにQtを使用しようとしています。
私が最初に焦点を当てようとしているのは、印刷プレビュー機能であり、QGraphicsTextItem と共に QGraphicsScene/View を使用すると考えました。
現在の問題は、QGraphicsTextItem の範囲内にテキストを含めることができないことです。テキストは、QGraphicsScene/View の一番下に到達するまで続きます。
QGraphics を使用することが正しい方法であるかどうか疑問に思っています。そうであれば、テキスト ドキュメントのページネーションを取得するにはどうすればよいですか?
添付の図に示す結果を生成するためのコード (PyQt、ただし、Python が優先されますが、C++ を理解できるはずです):
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_()*emphasized text*