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 know QTextEdit'height, when widget is hidden?

How to know QTextEdit'height, when widget is hidden?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 955 Views 1 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.
  • Q Offline
    Q Offline
    qwe3
    wrote on last edited by qwe3
    #1

    Hi,

    I have QWidget. I have to set on it many QTextEdits with textes, which I don't know ( they are from database ). I setFixedWidth in this QTextEdits to 200. I don't know their height. If text will be short, QTextEdits' height will be small etc. I need to know their height.

    There is very good method for me from QTextDocument. I do:

    document()->size();
    

    but this function works only when QTextEdits are visible! It works when QTextEdits are hidden but get me height = 0.
    I want other method to this the same, but when QTextEdits are hidden and get me real height ( not 0 ).

    JonBJ 1 Reply Last reply
    0
    • Q qwe3

      Hi,

      I have QWidget. I have to set on it many QTextEdits with textes, which I don't know ( they are from database ). I setFixedWidth in this QTextEdits to 200. I don't know their height. If text will be short, QTextEdits' height will be small etc. I need to know their height.

      There is very good method for me from QTextDocument. I do:

      document()->size();
      

      but this function works only when QTextEdits are visible! It works when QTextEdits are hidden but get me height = 0.
      I want other method to this the same, but when QTextEdits are hidden and get me real height ( not 0 ).

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @qwe3
      I don't know if this is right, but I would suspect you/Qt won't know QTextEdit height until it is shown, not if it's hidden....?

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qwe3
        wrote on last edited by
        #3

        @JonB Ok. But maybe there is a way to calculate this before "show()"?

        S 1 Reply Last reply
        0
        • nageshN Offline
          nageshN Offline
          nagesh
          wrote on last edited by nagesh
          #4

          @qwe3 if height to be adjusted automatically when it's visible, then set the vertical size policy: Expanding and set the line wrap mode
          https://doc.qt.io/qt-5/qtextedit.html#lineWrapMode-prop
          Can you explain the usecase of your requirement. Is there any reason to get the size when it's hidden?

          JonBJ 1 Reply Last reply
          0
          • nageshN nagesh

            @qwe3 if height to be adjusted automatically when it's visible, then set the vertical size policy: Expanding and set the line wrap mode
            https://doc.qt.io/qt-5/qtextedit.html#lineWrapMode-prop
            Can you explain the usecase of your requirement. Is there any reason to get the size when it's hidden?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @nagesh said in How to know QTextEdit'height, when widget is hidden?:

            set the vertical size policy: Expanding and set the line wrap mode

            How will that give the OP the total height of the QTextEdits?

            1 Reply Last reply
            0
            • nageshN Offline
              nageshN Offline
              nagesh
              wrote on last edited by nagesh
              #6

              @JonB I hope even that will not give valid height when it's hidden, I was just trying to tell in the way like if Layout & size policy is set height will be set automatically when it's visible. (post edited)

              1 Reply Last reply
              0
              • Q qwe3

                @JonB Ok. But maybe there is a way to calculate this before "show()"?

                S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #7

                @qwe3 said in How to know QTextEdit'height, when widget is hidden?:

                But maybe there is a way to calculate this before "show()"?

                I know that problem very well. So far, we have not found a solution to this than to show the widget first. Somehow the sizes of widgets inside a layout are not calculated before the widget is shown for the first time. There are two functions that are supposed to recalculate the layout (QLayout::update() and QWidget::adjustSize()), but they don't do anything in this context.

                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