Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make pages in QTextEdit or QPlainTextEdit
Forum Updated to NodeBB v4.3 + New Features

How to make pages in QTextEdit or QPlainTextEdit

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    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();
        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
    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • AmrCoderA Offline
        AmrCoderA Offline
        AmrCoder
        wrote on last edited by
        #3

        i add those before set the layout

            edit->setMinimumSize(500,500);
            edit1->setMinimumSize(500,500);
            edit2->setMinimumSize(500,500);
            edit3->setMinimumSize(500,500);
            edit4->setMinimumSize(500,500);
        

        and not work and the scrollbar still not working too

        mrjjM 1 Reply Last reply
        0
        • AmrCoderA AmrCoder

          i add those before set the layout

              edit->setMinimumSize(500,500);
              edit1->setMinimumSize(500,500);
              edit2->setMinimumSize(500,500);
              edit3->setMinimumSize(500,500);
              edit4->setMinimumSize(500,500);
          

          and not work and the scrollbar still not working too

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @AmrCoder
          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);
            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);
          
          1 Reply Last reply
          1
          • AmrCoderA Offline
            AmrCoderA Offline
            AmrCoder
            wrote on last edited by
            #5

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

            mrjjM 1 Reply Last reply
            0
            • AmrCoderA AmrCoder

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @AmrCoder
              I think you need to make a widget, put layout on that and
              insert edits there.
              then set widget to scroll area with
              scrollArea_2->setWidget(xxx)

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved