Resizing QT's QTextEdit to Match Text Height: maximumViewportSize() -


I'm trying to use a QTextEdit widget inside the form with many QT widgets. This form automatically sits inside a QSColaria which is the central widget for the window. My intention is that any required scrolling will be done in the main QScrollArea (instead of any widget), and any widget inside will automatically resize their height to keep their content.

I automatically resized the height with QTextEdit, but in a strange problem I have created a subclass QTextEdit and it has been re-implemented (like):

< Pre> QSize Operation Editor :: SizeHints () const {QSize sizehint = QTextBrowser :: sizeHint (); Sizehint.setHeight (this-> fitted_height); Return sizehint; }-> fitted_height is kept up-to-date through this slot, which is wired on QTextEdit's "Content Changed ()" signal: Pre> Zero Operation Editor: FitheitTodenu () {This-> Document () - & gt; Setadwidth (it-> viewport () - & gt; width ()); QSize document_size (this-> Document () -> Size (). ToSize ()); This- & gt; Fitted_height = document_size.height (); This- & gt; UpdateGeometry (); }

The QTextEdit sub-class size policy is:

  this-> set -ins policy (QSizePolicy :: MinimumExpanding, QSizePolicy :: favorites);  

I took this view after reading

Here's my problem:

As QEASTEdit gradually changes shape to fill the window , It grows up and starts scrolling within QTextEdit, no matter how much height has been returned from the shape hunt () if I get the shape initially () returns some large continuous numbers, So QTextEdit is too big and the external QScrollArea inserted well However, as one would expect, though, if the shape gradually adjusts the size of QTextEdit instead of actually making it big for starting, then it is at the top when it fills the current window and scrolls instead of moving Starts.

I have detected this problem, despite this, what is the hit of my size (), it will be as big as the QASTEdit, it will be more than the value of the maximum discriminates (), which QAbstractScrollArea is inherited from Note that this viewpoint () -> does not have the same number as maximum size (). I am unable to understand how to set that value.

Looking at QT's source code, the maximum viewview size () is returning the viewport size as if scroll bars do not have a valid scrolling range. " This value is originally calculated as the current size of widget degradation (2 * framewidth + margin) as well as any scrollbar width / height. It does not matter to me very much, and it is not clear to me that the number will be used anywhere in the manner that depends on the sub-section size (H.) implementation. In addition, it seems weird that singles The "framewidth" integer is used in both width and height.

Anyone put some light on this? I suspect that my poor understanding of Qt's layout engine is to blame here.

EDIT: After initially posting it, I had the idea of ​​retrieving maximal vivversis () as the shape hunt (). Unfortunately, this does not work because I still have the same problem.

I have solved this problem. To do this work, I had two things to do:

  1. Walking up the widget hierarchy and ensuring that all sizes of policies ensured that if any child wants a widget big To be smaller / younger, then the parents widget wants to be the same thing.

  2. This is the main source of this fixing it has come to know that QTextEdit is a hindrance in QScrollArea, since QTextEdit inside a main widget in QScrollArea, unless "widgetResizable "Property is not correct, it will not resize the internal widget. The document for this is here: The documentation was not clear to me as long as I did not play around this setting and got it to work. From documents, it seems that this property is only related to the time the main scroll area wants to resize a widget (i.e., from parent to child) it really means that if the main area of ​​the scroll area is ever Wants to change shape (i.e. child to parent), then this setting should be set to true.

The ethics of the story is that the QTextEdit code was correct in the hit overriding shape, but QScrollArea was ignoring the returned value of the main frame size hit.

Yes! Does it work!


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -