QGraphicsTextItem is too slow for long paragraphs

38 Views Asked by At

I`m trying to make simple text editor with Qt. I plan to use QGraphicsScene due to its greater opportunities than QTextEdit, QTextBrowser, etc. So, to begin with, I have prepared the simple example with QGraphicsTextItem:

#include <QApplication>
#include <QWidget>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QGraphicsView view;
    QGraphicsScene *scene = new QGraphicsScene;
    QGraphicsTextItem *text = new QGraphicsTextItem;

    text->setTextWidth(1020);
    text->setTextInteractionFlags(Qt::TextEditorInteraction);
    text->setFocus();

    scene->addItem(text);

    view.setScene(scene);
    view.show();

    return app.exec();
}

The application works well with formatted text: containg paragraphs and different styles. But when I try to write one long paragraph, it starts freezing already at ~200k symbols, which is quite small for my tasks. I assume this is due to the fact that Qt divides complex text into parts internally, but doesn`t do this for simple text of the same style. I have tried many flags but not a single piece of advice to speed up the QGraphicsScene helped me. Could you please tell me what should I do?

0

There are 0 best solutions below