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 code

        QVBoxLayout *layout =new QVBoxLayout();
        QTextEdit *edit = new QTextEdit("hello world");
        QTextEdit *edit1 = new QTextEdit("hello world");
        QTextEdit *edit2 = new QTextEdit("hello world");
        // i added more

    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
    alt text
    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

  • Qt Champions 2017

    You have to set minimumSize on the QTextEdit as
    not to have them become very small.
    Should be the size of a page.

  • i add those before set the layout


    and not work and the scrollbar still not working too

  • Qt Champions 2017

    That is odd.
    It works with no issues in Designer
    alt text

    When you draw it, it seems to create a widget (scrollAreaWidgetContents_2) and put layout on that

      scrollArea_2 = new QScrollArea(centralWidget);
      scrollAreaWidgetContents_2 = new QWidget();
      verticalLayout_2 = new QVBoxLayout(scrollAreaWidgetContents_2);
      textEdit = new QTextEdit(scrollAreaWidgetContents_2);
      textEdit->setMinimumSize(QSize(0, 500));

  • @mrjj can you please show me the code it not work for me i don't know why

  • Qt Champions 2017

    I think you need to make a widget, put layout on that and
    insert edits there.
    then set widget to scroll area with

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.