Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Solved How to make pages in QTextEdit or QPlainTextEdit

    General and Desktop
    2
    6
    1172
    Loading More Posts
    • 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.
    • AmrCoder
      AmrCoder last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • AmrCoder
          AmrCoder last edited by

          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

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @AmrCoder last edited by mrjj

            @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 Reply Quote 1
            • AmrCoder
              AmrCoder last edited by

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

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @AmrCoder last edited by mrjj

                @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 Reply Quote 1
                • First post
                  Last post