How to make pages in QTextEdit or QPlainTextEdit
-
Iam trying to make the look of pages in QTextEdit or using it to so each page has a limited number of lines per page and limited number of character per line and the first thing is the look and feel of pages
so I try to use this codeQVBoxLayout *layout =new QVBoxLayout(); ui->scrollArea->setLayout(layout); ui->scrollArea->setWidgetResizable(true); QTextEdit *edit = new QTextEdit("hello world"); edit->setSizePolicy(QSizePolicy::QSizePolicy::Preferred,QSizePolicy::Preferred); QTextEdit *edit1 = new QTextEdit("hello world"); edit1->setSizePolicy(QSizePolicy::QSizePolicy::Preferred,QSizePolicy::Preferred); QTextEdit *edit2 = new QTextEdit("hello world"); edit2->setSizePolicy(QSizePolicy::QSizePolicy::Preferred,QSizePolicy::Preferred); // i added more layout->addWidget(edit); layout->addWidget(edit1); layout->addWidget(edit2);
this code is simple just use scrollbar container and add it vertical layout and every time I need a page make a new QTextEdit and add it to the vertical layout in the scrollbar
the problem here is that whenever I add a new page the QTextEdit I add it so too small and the scrollbar never work on it so that the QTextEdit be above each other so it makes a bad look
so what I make wrong so that the scrollbar not working and how to make each QTextEdit take a good page look which has a good size to give me the look of something like Microsoft word or pdf which have pages
also if there is a better idea or a solution to what iam trying to do it will be better if there is an already implemented widget or library have this.
Thanks in advance -
Hi
You have to set minimumSize on the QTextEdit as
not to have them become very small.
Should be the size of a page. -
-
@AmrCoder
That is odd.
It works with no issues in Designer
When you draw it, it seems to create a widget (scrollAreaWidgetContents_2) and put layout on that
scrollArea_2 = new QScrollArea(centralWidget); scrollArea_2->setWidgetResizable(true); scrollAreaWidgetContents_2 = new QWidget(); verticalLayout_2 = new QVBoxLayout(scrollAreaWidgetContents_2); textEdit = new QTextEdit(scrollAreaWidgetContents_2); textEdit->setMinimumSize(QSize(0, 500)); verticalLayout_2->addWidget(textEdit); scrollArea_2->setWidget(scrollAreaWidgetContents_2);