PDA

View Full Version : QDialog and resizing problem...



TemporalBeing
10th February 2009, 22:26
I'm relatively new to this - just been doing Qt4 for a little over a week, so please forgive me if this is something is seemingly obvious to the more skilled. I've really grown to love Qt - it's just so much more logical and well planned than MFC, Win32, or anything else I've worked with.

FYI - I'm using Qt 4.4.3, Windows Commercial, under VS2008.

I'm having a trouble with a dialog resizing on me. I'm already using several layout managers - added through QtDesigner - as follows:

Side Bar:
+-------------------------+
| <fix vertical> | <- fixed to keep height from top the same
| button |
| <expanding vertical> |
|<fix horizontal> | <- to line up with the lower bar, fixed to keep width the same
+-------------------------+


Lower Bar:
+----------------------------------------------------------------+
| <expanding horizontal> button <expanding horizontal> |
+----------------------------------------------------------------+

Central Bar:

+-----------------+
| QTableWidget |
+-----------------+
| Lower Bar |
+-----------------+

Main Layout of QDialog:

+-----------+--------------+
| Side Bar | Central Bar |
+-----------+--------------+


My problem is that the QDialog gets resized whenever I insert a row into the QTableWidget (via QTableWidget::insertRow()).

Aside from the specifically fixed bars, everything is set to have an QSizePolicy::Expanding size policy, and the size constraints have been set to QLayout::SetNoConstraint.

The odd behaviour is that the QDialog will shrink below even the size of QTableWidget if I have a minimum size set in the QTableWidget - cutting off the vertical scroll bar.

It will somewhat abide by a minimum size if I set it - but then the dialog is way too big, and I'd really like to be able to let the user resize the dialog.

I had had a minimum width set for a while, but the resize issue would still occur as it would resize away any height I had added - meaning I would have to resize only after I had added all the rows I wanted.

Any tips, help, etc. would be greatly appreciated.

TIA,

Ben

talk2amulya
11th February 2009, 17:50
sounds like the dialog isnt set as the parent of the other widgets..otherwise thats a really odd behaviour..are u sure dialog is the parent of all other widgets and spacers

TemporalBeing
11th February 2009, 22:49
sounds like the dialog isnt set as the parent of the other widgets..otherwise thats a really odd behaviour..are u sure dialog is the parent of all other widgets and spacers

Pretty sure...

I've tried adding a new QVBoxLayout that tries to take over the main layout as a child - namely because I also added a menu bar that is not a child of any of the other layouts, and was trying to fit it in as well in trying to resolve this.[1] Any how...in doing so, it complains about already having a parent when I do so. Taking out that code doesn't change the behavior, nor does adding it fix it. (Just changed and checked to verify.)

I added all the widgets via the Qt Designer, and looking at the UIC generated code (namely the implementation of ui.setup(this)) it seems like things would parent correctly.


[1] The menu bar was added via the following:
menuBar = new QMenuBar(this);

It's only oddity is the bottom of the text sits a little lower than the top of the QTableWidget. I figured this was probably due to its lack of inclusion in the UI's layout, but it doesn't seem to be programmatically solvable by adding another layout.

talk2amulya
12th February 2009, 05:43
Could u please post the relevant code..its really hard to guess the problem, although i think it will be a really trivial one

TemporalBeing
12th February 2009, 21:46
Could u please post the relevant code..its really hard to guess the problem, although i think it will be a really trivial one

I'll see what I can do. The program is already complete aside from this issue, and I don't think they'd let me just post it. So I'll see if I can create another one that I can post and exhibits the same issue.

TemporalBeing
2nd March 2009, 14:52
Ok...found the issue.

Essentially, I had setup a call to adjustSize() when inserting a row. The call would then shrink the dialog to its _minimum_ size. However, my expectation was that the layout would inquire of the table its minimum size and the table would consider the contents and make an appropriate adjustment so the dialog would not be extremely out of proportion with its data up to the screen resolution available. However, none of that seems to happen, so it just goes it minimum size.

Eliminating the adjustSize() call fixes the issue. Is there any way to do what I was expecting it to do?

Then again, thinking about it now...that's probably something undesirable from the user's pov...one of those things that has a good intention but a bad effect...

TIA,

Ben

TemporalBeing
27th March 2009, 15:14
I figured out how to reproduce it now. Below is a link to some sample code. Note the code around 'table->insert(...)'. The 'adjustSize()' doesn't seem to bother it, but the calls to adjusting the table size information do. I tested this project on Windows using Qt 4.4.3, but I'm sure it would work the same under Linux too.

http://tinyurl.com/cfa5w4

Essentially, what I wanted was to be able to adjust the table cells to the contents, and let the user decide about the size of the dialog. However, doing so seems to adversely affect the size of the dialog itself.

TemporalBeing
27th March 2009, 15:16
Sorry, should have done this as part of the last post...occurred to me just as I hit the 'quick reply' button...

For completeness - as I'm not going to keep that tarball online forever - here's the specific code that I added to cause the problem again:



void testTable::doInsertRow()
{
if (table != NULL)
{
table->insertRow(table->rowCount());
table->resizeColumnsToContents();
table->resizeRowsToContents();
table->adjustSize();
}
adjustSize();
}