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] Getting size of viewable aread of QTextEdit
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Getting size of viewable aread of QTextEdit

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.5k 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.
  • V Offline
    V Offline
    voidtrance
    wrote on last edited by voidtrance
    #1

    Hi all,

    I'd like to get the size of the viewable area of QTextWidget. What I mean by "viewable area" is the window in which the user can see the document content. This viewable area does not include the scrollbars (if they are shown), just the content windows.

    The layout of the application is such that I have a QTabWidget which contains the QTextEditor widget. So what I would expect to happen is that if I do the following sequence:

    1. Open a new tab
    2. Resize application window
    3. Open a new tab

    the tabs opened at step 1 and 3 would show a difference size. However, they don't. The sizes returned by QWidget.size() on both the editor widgets are the same.

    I don't understand how that could be. Any help?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      voidtrance
      wrote on last edited by
      #2

      Any ideas on how I can get the size I am looking for?

      mrjjM 1 Reply Last reply
      0
      • V voidtrance

        Any ideas on how I can get the size I am looking for?

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

        @voidtrance

        Have a look at QTextDocument::size()
        You get from the document() function.

        This is just guessing. Did not code test it :)

        V 1 Reply Last reply
        0
        • mrjjM mrjj

          @voidtrance

          Have a look at QTextDocument::size()
          You get from the document() function.

          This is just guessing. Did not code test it :)

          V Offline
          V Offline
          voidtrance
          wrote on last edited by
          #4

          @mrjj said:

          @voidtrance

          Have a look at QTextDocument::size()
          You get from the document() function.

          This is just guessing. Did not code test it :)

          I am not exactly sure what QTextDocument::size() returns but it is not the size of the visible area of the document. In fact, if I follow the same procedure as in the original post, the size printed return by QTextDocument::size() is exactly the same regardless of the fact that the visible area has been shrunk to about 25%.

          mrjjM 1 Reply Last reply
          0
          • V voidtrance

            @mrjj said:

            @voidtrance

            Have a look at QTextDocument::size()
            You get from the document() function.

            This is just guessing. Did not code test it :)

            I am not exactly sure what QTextDocument::size() returns but it is not the size of the visible area of the document. In fact, if I follow the same procedure as in the original post, the size printed return by QTextDocument::size() is exactly the same regardless of the fact that the visible area has been shrunk to about 25%.

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

            @voidtrance
            And you have set a layout so that the editor auto adjust to the size of the tab widget and the form
            also has a layout that makes the tabwidget auto adjust to the size of the form?

            I must be doing something wrong here as
            ui->textEdit->size().width();

            Does report different sizes when i resize the form.

            sorry for not understanding.

            V 1 Reply Last reply
            0
            • mrjjM mrjj

              @voidtrance
              And you have set a layout so that the editor auto adjust to the size of the tab widget and the form
              also has a layout that makes the tabwidget auto adjust to the size of the form?

              I must be doing something wrong here as
              ui->textEdit->size().width();

              Does report different sizes when i resize the form.

              sorry for not understanding.

              V Offline
              V Offline
              voidtrance
              wrote on last edited by
              #6

              @mrjj said:

              @voidtrance
              And you have set a layout so that the editor auto adjust to the size of the tab widget and the form
              also has a layout that makes the tabwidget auto adjust to the size of the form?

              I must be doing something wrong here as
              ui->textEdit->size().width();

              Does report different sizes when i resize the form.

              sorry for not understanding.

              I am a little confused about your question regarding layouts but as far as I know everything is setup correctly.

              The QTextEdit widget in question is embedded in several layers of other widgets but they all have their layouts set correctly. The QTextEdit widget properly changes when I am resize the main window. Also, the scrollbars properly resize themselves to represent the chunk of visible content when I resize the main window.

              All of that leads me to believe that I have them embedded properly. However, QTextEdit->size() still returns the same size regardless. Therefore, I am thinking that I am doing something wrong. I'll investigate further.

              mrjjM 1 Reply Last reply
              0
              • V voidtrance

                @mrjj said:

                @voidtrance
                And you have set a layout so that the editor auto adjust to the size of the tab widget and the form
                also has a layout that makes the tabwidget auto adjust to the size of the form?

                I must be doing something wrong here as
                ui->textEdit->size().width();

                Does report different sizes when i resize the form.

                sorry for not understanding.

                I am a little confused about your question regarding layouts but as far as I know everything is setup correctly.

                The QTextEdit widget in question is embedded in several layers of other widgets but they all have their layouts set correctly. The QTextEdit widget properly changes when I am resize the main window. Also, the scrollbars properly resize themselves to represent the chunk of visible content when I resize the main window.

                All of that leads me to believe that I have them embedded properly. However, QTextEdit->size() still returns the same size regardless. Therefore, I am thinking that I am doing something wrong. I'll investigate further.

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

                @voidtrance
                Ok. what Im asking is if you setup the layouts but from your answer,
                it seems you have them setup and working as
                expected.

                My mini test must be wrong in some regards as Size() before and after resize mainwindow does
                give changed values.

                If you make a mini sample using the forms editor and just placing a tabwidget
                and give it 2 tabs with TextEdits, does size() then give you expected values?

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  voidtrance
                  wrote on last edited by
                  #8

                  OK, well, I feel dumb!

                  The reason why the size printed every time was the same is because I was printing the size prior to the QTextEdit widget receiving its initial resizeEvent(). Therefore, I kept getting some default size and not the actual size after Qt had properly placed the widget.

                  Marking as SOLVED.

                  mrjjM 1 Reply Last reply
                  0
                  • V voidtrance

                    OK, well, I feel dumb!

                    The reason why the size printed every time was the same is because I was printing the size prior to the QTextEdit widget receiving its initial resizeEvent(). Therefore, I kept getting some default size and not the actual size after Qt had properly placed the widget.

                    Marking as SOLVED.

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

                    @voidtrance
                    Ahh. And since i did via a button, i was way past resizeEvent()

                    Thank you for updating.

                    1 Reply Last reply
                    0

                    • Login

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