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. [SOLVED] Creating editor without scrolling
QtWS25 Last Chance

[SOLVED] Creating editor without scrolling

Scheduled Pinned Locked Moved General and Desktop
qabstracttextdoqplaintextedit
6 Posts 2 Posters 1.9k Views
  • 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.
  • Y Offline
    Y Offline
    Yakov Eremin
    wrote on 31 Jul 2015, 07:15 last edited by Yakov Eremin
    #1

    Hello!
    I want to create editor, which will change it's size for content (without scroll). I take QPlainTextEdit, and make next connection:

    connect(ui->plainTextEdit->document()->documentLayout(), 
    SIGNAL(documentSizeChanged(QSizeF)),
    SLOT(editorSizeChanged(QSizeF)));
    

    And in slot I take received height, and multiply it to pixels height of one line:

     QFont font("", 0);
     QFontMetrics fm(font);
     int pixelsHigh = fm.lineSpacing(); 
     ui->plainTextEdit->setFixedHeight((inSize.height()+1)*pixelsHigh);
    

    This construction works perfectly until we have < 5 lines in editor. After that in the bottom of the editor appears extra space, and scrollbar at right.

    What i'm doing wrong ?
    Minimal example

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 31 Jul 2015, 11:12 last edited by mrjj
      #2

      Hi and welcome
      Have a look at
      QAbstractScrollArea::setVerticalScrollBarPolicy()
      QAbstractScrollArea::setHorizontalScrollBarPolicy( )

      and the Qt::ScrollBarAlwaysOff value

      Y 1 Reply Last reply 31 Jul 2015, 12:46
      0
      • M mrjj
        31 Jul 2015, 11:12

        Hi and welcome
        Have a look at
        QAbstractScrollArea::setVerticalScrollBarPolicy()
        QAbstractScrollArea::setHorizontalScrollBarPolicy( )

        and the Qt::ScrollBarAlwaysOff value

        Y Offline
        Y Offline
        Yakov Eremin
        wrote on 31 Jul 2015, 12:46 last edited by
        #3

        @mrjj scrollbars already disabled in Qt Designer. Problem actually in extra space, which causes incorrect size computing.

        M 1 Reply Last reply 31 Jul 2015, 14:01
        0
        • Y Yakov Eremin
          31 Jul 2015, 12:46

          @mrjj scrollbars already disabled in Qt Designer. Problem actually in extra space, which causes incorrect size computing.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 31 Jul 2015, 14:01 last edited by
          #4

          @Yakov-Eremin
          hi
          I think your issue is that you use another font for getting line height than the actual editor and
          since you multiply then slowly the space grows.

          try with

          void MainWindow::editorSizeChanged(QSizeF inSize)
          {
          QFont font=ui->plainTextEdit->font();
          .....

          Y 1 Reply Last reply 31 Jul 2015, 14:28
          1
          • M mrjj
            31 Jul 2015, 14:01

            @Yakov-Eremin
            hi
            I think your issue is that you use another font for getting line height than the actual editor and
            since you multiply then slowly the space grows.

            try with

            void MainWindow::editorSizeChanged(QSizeF inSize)
            {
            QFont font=ui->plainTextEdit->font();
            .....

            Y Offline
            Y Offline
            Yakov Eremin
            wrote on 31 Jul 2015, 14:28 last edited by
            #5

            @mrjj thank you, the problem is solved

            M 1 Reply Last reply 31 Jul 2015, 14:38
            0
            • Y Yakov Eremin
              31 Jul 2015, 14:28

              @mrjj thank you, the problem is solved

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 31 Jul 2015, 14:38 last edited by
              #6

              @Yakov-Eremin
              you're welcome.
              Very good with the mini sample !

              1 Reply Last reply
              0

              6/6

              31 Jul 2015, 14:38

              • Login

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