PDA

View Full Version : Resizing a QDialog to the content size



Nyphel
14th March 2007, 09:39
Hello,

I have a QDialog based ui.
The QDialog only contains a QTableWidget within a QVBoxLayout.

My table is compouned of an unknown number of rows, and I resize them with "resizeRowsToContents()" every time the content of the table has changed.
That's ok.

The problem is to resize the height of the QDialog to match the new size of the table.
In order to do that, I sum the height of the rows and I get the size really used by the table.

So, I just need to resize my QDialog...
It's new height will be equals to the table's necessary height more any pixels for the QDialog's style (that adds border on the top and the bottom of the content, for title, menus, etc...).

I can't find any function that would give me the avaible geometry of the QDialog, in order to compute :
Added height = QDialog's height - avaible geometry.height
So I compute something like :
Added height = QDialog's height - QTable's height

The matter is that the QTable->height doensn't give me the height of the Widget.
It returns me 30.
The sum of the rows is about 66.
The QTable size is about 180. (I know that with the QDesigner)
The QDialog size is about 200. (I know that with the QDesigner)

I used the size() and geometry() functions in order to get the QTable's height.
Every time I try to know the height value, I get 30 :eek:

May you help me please ?

Lykurg
14th March 2007, 10:09
Hi,

maybe adjustSize() works for you.

Lykurg

wysota
14th March 2007, 10:32
You can't retrieve the size of a widget before it is shown for the first time.

Nyphel
14th March 2007, 10:34
If I show it one, two... three times before getting the size, i've got the same result :(.
I'll try "adjustSize()" :)

jpn
14th March 2007, 10:43
If I show it one, two... three times before getting the size, i've got the same result :(.
A widget is not shown immediately after calling show(). A show event is scheduled and the widget comes visible later when the control returns to the event loop.

wysota
14th March 2007, 12:04
You can override showEvent() and set the size there if you want.

Nyphel
14th March 2007, 15:06
Oki, thanks.

I override the showEvent and now it works fine.
I set fit the columns/rows size to the content, and then I fit the QDialog to the QTable content size.

I don't understand why that didn't work before.
I'm sure that the QDialog was shown before trying to resize it :( .

Thanks everybody :)

wysota
14th March 2007, 15:33
How did you make sure it was shown before resizing it?

Nyphel
15th March 2007, 08:16
Because I show it with a button,
and then I push another button to resize it ^_^