View Full Version : Expanding textedit field strange behaviour

23rd October 2007, 09:49
A Tabbed widget consisting of a bunch of line edits and text edits laid out in a grid layout. All the text edit fields have a max height except one.
With Qt Designer, it looks ok, and I can resize it by dragging the corners with the mouse.
If I preview the form, it takes on an expanded size. It's the text edit widget with default max size that is expanding and I can't resize the form to the same size as it is in designer.
Can anyone provide any ideas how to fix this behaviour ?

23rd October 2007, 10:34
I just tried what you described and have no such effect.
Just to be sure about your setup, since it was a bit confusing:
You have several QTextEdits on a form, in a grid layout.
All the text edit have maximal hight, except one.
I have no trouble resizing the from in preview mode with the above details.

23rd October 2007, 11:00
Also if all widgets are in a layout, you shouldn't be able to freely resize them manually when designing. So if you can, one of the widgets is probably not managed by a layout.

24th October 2007, 00:25
I've attached an example.
Open with Qt designer, apply grid layout to the tabbed page and see what I mean.

24th October 2007, 00:32
Oh... you mean that. Change the vertical size policy of the text edit to Preferred or Maximum.

24th October 2007, 11:46
No, that doesn't do it, it still expands to it's own liking, it seems to do it's own thing.
Even if I change it's sizePolicy to Fixed, it actually expands even more :confused:

The example is just one page of the finished form, I deleted everything else to elliminate other objects, and in fact the whole thing is basically out of control. I can't seem to define a preferred size for the textEdit items, they just expand as they like. Then if I edit their size I find I can't resize the layout beyond where the textEntry's expanded size was. I could attach the whole part if need be.

24th October 2007, 11:54
well, if I use the ui you posted, and apply size vertical policy 'preferred' I can resize the form in preview mode just like I can in design mode...

did you try that with the ui you posted?

24th October 2007, 12:30
Yes I did try it, and no, that doesn't happen here. As soon as I apply a grid layout to the page the textEdit jumps from 65 to a vertical height of 96.

24th October 2007, 13:40
I tried it with QSizePolicy::Preferred and it works fine and behaves in the preview just like it does in Designer. Which version of Qt do you use? I am using Qt-4.3.1 on Windows here. i'll check it on Linux later on when I get home.

24th October 2007, 13:52
Version Qt-4.3.0
You mean it doesn't change size on you at all ?

24th October 2007, 13:58
If I squeez the widget down to the smallest possible height, the bottom text edit has a height of 63. If I switch into previewmode then, the height remains the same. Of course I can increase the size of the Widget, which results in a higher text edit. But its just the behaviour one would expect. The size does not jump from 63 to 96 pixels when running the preview. I'll get home in 5 hours and will post a screencast if you haven't solved it until then.

24th October 2007, 15:29
Yes thank you, let me know how it behaves for you. I've tried everything and have hit a brick wall.

I mean to say, I don't have to preview the form for the results, it resizes right there in Qt Designer as soon as I apply the grid layout. That's what's strange about this.

I just re-opened it to check my facts and now I've noticed another strange behavior.

I open the example form, the textedit is at height 65. There is no layout manager assigned yet.

I go to manually resize the field down even smaller with the mouse, and it immediately resizes itself to 94, and I can't reduce it's size with the mouse, only by the property editor. Could I have uncovered a bug ?

24th October 2007, 15:40
Could I have uncovered a bug ?
I don't think so, since then we could have reproduced it.
Did you try this with the ui you posted? with the very same file?

24th October 2007, 20:26
Does the file in attachment behave correctlly? Note that you can't decrease the size of the widget more than the minimumSizeHint. If you want to override the minimumSizeHint, please provide a correct value for minimumSize property like I did in the attachment.

25th October 2007, 05:50
Vieraci, seems like you were right.
Just tried it on linux and the size jumpes up to 96 from 65 upon applying the gridlayout. I've created a screenshot that can be found here: http://www.informatik.uni-bremen.de/~momesana/geometry-issue.ogg.
I didn't have this problem on windows though. I may test it on the windows partition of my notebook later on and give more details if I find the time.

25th October 2007, 07:53
Thanks again wysota, minimum size fixed the problem, BUT when I embed the composite part into the main menu part, it expands like it did before !
I found setting the tabbed widget's minimum size in the main menu's constructor fixed it.

momesana confirmed it acts differently under windows thou,

25th October 2007, 09:13
Menu? You want the widget to be part of the menu?

I think you are doing some weird things and so the layout doesn't behave exactly as you'd like it to. I'm not exactly sure what you are trying to do, so it's hard for me to comment that...

25th October 2007, 12:48
Hey hold on there... nothing like it !!

Nothing to do with "the" menu system. It's what I called my app's main window, "mainMenu" :cool:

25th October 2007, 17:59
I'm still not sure I follow you... Doesn't this work?

26th October 2007, 00:00
Yes it works fine on it's own, here is constructor code where I use it...

MainMenu::MainMenu(QWidget *parent)
: QMainWindow(parent)
setupUi( this );
// create Logon stacked widget page and add the logon dialog to it
logonPage = new QWidget();
logonBoxLayout = new QHBoxLayout(logonPage);
logonUI = new logonui(this);
QObject::connect(logonUI, SIGNAL(okClicked()),
this, SLOT(logon()));

// Create clientEditPage
clientEditPage = new QWidget();
clientEditPageGridLayout = new QGridLayout(clientEditPage);
clientDetailsNoteBook = new ClientNotebook(this);

// Here, set min size so last textEdit doesn't blow out

In 2nd last line I set min size because text edit STILL wants to grow.

26th October 2007, 00:40
I don't see you changing its size policy... that's the key to the whole concept, you know...

26th October 2007, 08:35
I don't see you changing its size policy... that's the key to the whole concept, you know...

er..no, I don't know, I'm still fairly new to Qt, and yes, that worked too.
So changing size policy is preferrable to resizing ?
I think I understand why, sizePolicy isn't hard-coding a value... right ?

clientDetailsNoteBook->setSizePolicy(QSizePolicy::Preferred,QSizePolicy:: Preferred);

26th October 2007, 09:08
Size policy is the first thing to adjust when you want to change the behaviour of a layout. The next step is changing the horizontal and vertical stretch and only the last one is to force a size (be it minimum or maximum). In most cases changing the policy is sufficient.