Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, July 2007
QTextEdit::setMinimumHeight() broken?


Message 1 in thread

Ok, now I have my QSplitter problems almost completely fixed. The only thing
that remains is that QTextEdit does seem to override the minimum height I
set. When I have a vertical layout with two widgets, the lower one being a
QTextEdit, the upper one with QSizePolicy::Expanding, and the QTextEdit
with QSizePolicy::Maximum, the QTextEdit will be larger than the minimum
height of 100 px that I have set. If I use a QFrame instead of the
QTextEdit, this works. Does QTextEdit have some undocumented maximal
minimum height? I can set a fixed height which is smaller, but that's not
what I want.

Regards,

Arne

-- 
 [ signature omitted ] 

Message 2 in thread

On 7/31/07, Arne Schmitz <arne.schmitz@xxxxxxx> wrote:
>
> Ok, now I have my QSplitter problems almost completely fixed. The only
> thing
> that remains is that QTextEdit does seem to override the minimum height I
> set. When I have a vertical layout with two widgets, the lower one being a
> QTextEdit, the upper one with QSizePolicy::Expanding, and the QTextEdit
> with QSizePolicy::Maximum, the QTextEdit will be larger than the minimum
> height of 100 px that I have set. If I use a QFrame instead of the
> QTextEdit, this works. Does QTextEdit have some undocumented maximal
> minimum height? I can set a fixed height which is smaller, but that's not
> what I want.


Can you post a minimal, compilable example that shows this behavior? From
your description, it sounds like it should just be main() creating a few
widgets and setting a few properties on them.

Tom

Message 3 in thread

Tom Panning wrote:

> Can you post a minimal, compilable example that shows this behavior? From
> your description, it sounds like it should just be main() creating a few
> widgets and setting a few properties on them.

Sure look at this:

------------------SNIP----------------
#include <QApplication>
#include <QSplitter>
#include <QTextEdit>
#include <QSizePolicy>

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    QSplitter* splitter = new QSplitter;
    splitter->setOrientation(Qt::Vertical);
    QTextEdit* upper = new QTextEdit(splitter);
    QTextEdit* lower = new QTextEdit(splitter);

    lower->setMinimumHeight(50);

    QSizePolicy policy;
    policy = upper->sizePolicy();
    policy.setVerticalPolicy(QSizePolicy::Expanding);
    upper->setSizePolicy(policy);
    policy = lower->sizePolicy();
    policy.setVerticalPolicy(QSizePolicy::Maximum);
    lower->setSizePolicy(policy);

    const int UPPER_INDEX = 0;
    const int LOWER_INDEX = 1;
    const int NO_STRETCH = 0;
    const int STRETCHABLE = 1;

    splitter->setStretchFactor(UPPER_INDEX, STRETCHABLE);
    splitter->setStretchFactor(LOWER_INDEX, NO_STRETCH);
    splitter->show();

    return app.exec();
}
------------------SNIP----------------

Regards,

Arne

-- 
 [ signature omitted ] 

Message 4 in thread

Arne,
I ran your code, and setMinimumHeight() seems to be working properly. The
splitter will not resize the lower widget to 50 pixels tall, but no shorter.
I did notice that "policy.setVerticalPolicy(QSizePolicy::Maximum);" doesn't
seem to affect the maximum height, but size policies affect how the widget
interprets sizeHint() and have almost nothing to do with setMinimumHeight().
Your original email says that "the QTextEdit will be larger than the minimum
height of 100 px that I have set", which sounds like desirable behavior: if
you set a minimum height, then I would expect the widget to be larger.

What is the desired behavior for the code example?
Tom

Message 5 in thread

Tom Panning schrieb:

> I ran your code, and setMinimumHeight() seems to be working properly. The
> splitter will not resize the lower widget to 50 pixels tall, but no
> shorter. I did notice that
> "policy.setVerticalPolicy(QSizePolicy::Maximum);" doesn't seem to affect
> the maximum height, but size policies affect how the widget interprets
> sizeHint() and have almost nothing to do with setMinimumHeight(). Your
> original email says that "the QTextEdit will be larger than the minimum
> height of 100 px that I have set", which sounds like desirable behavior:
> if you set a minimum height, then I would expect the widget to be larger.
> 
> What is the desired behavior for the code example?

The documentation to QSizePolicy::Maximum says:

"The sizeHint() is a maximum. The widget can be shrunk any amount without
detriment if other widgets need the space (e.g. a separator line). It
cannot be larger than the size provided by sizeHint()."

Hm, for every other widget the minimum height is taken as the size hint. So
I expected the QTextEdit to be 100 px high. So what I want to have is:

The example from before, but the lower widget to be 100 px high by default,
and not resized, except by the user, using the QSplitter.

Thanks,

Arne

-- 
 [ signature omitted ] 

Message 6 in thread

On 7/31/07, Arne Schmitz <arne.schmitz@xxxxxxx> wrote:
>
> The documentation to QSizePolicy::Maximum says:
>
> "The sizeHint() is a maximum. The widget can be shrunk any amount without
> detriment if other widgets need the space (e.g. a separator line). It
> cannot be larger than the size provided by sizeHint()."
>
> Hm, for every other widget the minimum height is taken as the size hint.
> So
> I expected the QTextEdit to be 100 px high.


I really wouldn't count on that relationship between the minimum height and
the size hint. The only way I know to change the size hint is to subclass
and reimplement the method.

The example from before, but the lower widget to be 100 px high by default,
> and not resized, except by the user, using the QSplitter.


If all you want is the lower widget to be 100px tall initially, then this
code will do that using QSplitter::setSizes():

#include <QApplication>
#include <QSplitter>
#include <QTextEdit>
#include <QSizePolicy>

#include <QtDebug>

int main(int argc, char** argv)
{
   QApplication app(argc, argv);
   QSplitter* splitter = new QSplitter;
   splitter->setOrientation(Qt::Vertical);
   QTextEdit* upper = new QTextEdit(splitter);
   QTextEdit* lower = new QTextEdit(splitter);

   const int UPPER_INDEX = 0;
   const int LOWER_INDEX = 1;
   const int NO_STRETCH = 0;
   const int STRETCHABLE = 1;

   splitter->setStretchFactor(UPPER_INDEX, STRETCHABLE);
   splitter->setStretchFactor(LOWER_INDEX, NO_STRETCH);

   // Make the lower widget 100px tall. We have to assign a
   // size to the upper widget (and anything less than or
   // equal to 0 causes the upper widget to be collapsed),
   // but it doesn't matter what size we use, because the
   // upper widget has all the stretch and will be resized
   // automatically during the show.
   QList<int> sizes;
   sizes << 1 << 100;
   splitter->setSizes(sizes);

   qDebug() << "Sizes before showing:" << splitter->sizes();

   splitter->show();

   qDebug() << "Sizes after showing:" << splitter->sizes();

   return app.exec();
}

Message 7 in thread

Tom Panning schrieb:

> If all you want is the lower widget to be 100px tall initially, then this
> code will do that using QSplitter::setSizes():

Ah! I have obviously overlooked that. Thank you. I am still learning a lot
Qt tricks every day.

Case closed, thanks for the answers. :-)

Arne

-- 
 [ signature omitted ]