PDA

View Full Version : Designing a QGridLayout of QTextEdits



Ponnytail
25th November 2013, 15:02
I've ran into some strange grid layout issue in my program. Instead of pasting the whole program I'm gonna show a few examples which hopefully describes the problem well enough.

Example #1.
Consider a 12x12 grid containing 9 buttons each spanning over 4 rows and 4 columns with a side length of 100 pixels. By forcing the minimum height to be 100 we get the following result:

9818

Example #2
Now I want to split up button 4 and 5. I want button 4.1 to have a height of 25 and span over 1 row and button 4.2 to have a height of 75 and span over 3 rows. Other way around for button 5. Easily done and the result is as expected:

9819

Example #3
That was buttons. In my program the grid contains a lot of QTextEdits which seem to cause strange errors. Lets say I want to try out example #2 again but use QTextEdit instead of QPushButton. By telling the text edits which minimum height they should have, the result is strange:

9820

In the picture, the result is clearly not what I wanted. Text edit 4 and 7 should only span over 1 row but in the picture it seems like they span over equally as many as text edit 5 and 6 which is 3 rows. What's wrong here?

Example #4
Confused by the behaviour I tried to use maximum height instead of minimum height and give text edit 4 and 7 a maximum height of 25. The result doesn't make sense at all:

9817

This displays what happens in my program. Although text edit 5 and 6 are forced to have a minimum height of 75 they are now only 25. Also text edit 8 seem to have happily adapted to the magic that's going on and have gained itself a height of 50 even though it's forced to be a minimum of 100.

I'd very much appreciate if anyone could tell me the reason why example 3 and 4 behave like they do. A code example would be awesome as well. I know grids can be tricky but because it works fine with buttons I think QTextEdit is the troublemaker here.

Thanks!