PDA

View Full Version : Hidden QDialog : force the update() or repaint()



Nyphel
17th April 2007, 12:26
Hi,

I've some Qdialogs generated in a loop. The implementation class of the QDialogs resize them to fit the content.
Each QDialog is shown.

At the end of the loop I want them to have the same width.
So, each of them give me his width, and I resize them to the width max unsing resize(int, int).

After that, I want them to be displayed in Windows cascade style : each QDialog must be just under the previous (small padding bottom and small paddin right)... And I do this using setGeometry(int, int, int, int).

That's ok : everything works well.
Now I don't show the QDialogs in the loop : the user won't understand why his frames are resized and moved on the screen... So I let them hidden during the work.
At the end a show each of them, but they are no more resized :(.

Reading the documentation, I understood that the update() and repaint() slots aren't used if the widget is hdden... But they add :

If the widget is not currently visible, it is guaranteed to receive an event before it is shown.
The problem is that my moveEvent seems to be received, but not the resizeEvent().

Is there a solution to hide them, work on their size/position, and show them correctly ?

PS : I've already reimplemented the show()/resize() events of the QDialogs ine the implementation class, in order that they automaticaly adjust the frame to the content, or the content to the frame if it is resized by the user.

wysota
17th April 2007, 13:19
Could you explain that loop thing again? Maybe a screenshot is needed?

Nyphel
17th April 2007, 13:49
I can't post screenshots, sorry :)


1) I have an implementation class <A>, that herits from QDialog.
This class create a QDialog that contains some text, a QTableWidget en 2 buttons.
The QTableWidget is updated, anf filled with some data (e-mails).
I have reimplemented the showEvent() en resizeEvent() in order :
- to fit the QDialog (and it's QTableWidget) to the content
- to adjust the QTableWidget size (and content display) when the user resize the QDialog

2) In my application, I've a loop that creates <A> objects and give them some data : 1 cycle of loop by e-mail account.
Immediatly, each <A> object will be auto-resized to fit to its content.
My application store the <A> objects in a QList<A> *.

3) I show thoses <A> objects.

4) I want all <A> objects to have the same width.
I look at each one, store the max width, and resize all the <A> objects to the max widt I've found. Like the <A> objects are visible, this works well.

5) I want a best display of my <A> objects : a Windows cascade style is nice :).
So I move them, using the setGeometry(int, int, int, int) function. Like the <A> objects are visible, this works well.




Now I would like to do the same job, but the <A> objects would be hidden.
Like they are hidden, the moveEvent() and resizeEvent() are managed by Qt, but the documentation says that :

If the widget is not currently visible, it is guaranteed to receive appropriate events before it is shown.

So, I do the same job, but I don't show the <A> objects.
At the end of the job, after the 5) point, I show them : they have been moved correctly, but not resized ike they should have been...

Nyphel
18th April 2007, 08:18
I will simply reuse the showEvent.

Simply holds position and size data in variables.
When I enter the showEvent, if those data aren't equals to 0, I'll use them and set variables to 0.

wysota
18th April 2007, 08:34
I would use the sizeHint() to force the dialog to a proper width. If you change the sizeHint() and apply a constraint on the layout of the widget (dialog, in your case), Qt will make sure it is sized properly. Then it doesn't matter if the widget is hidden or not - it'll get resized when needed.

Nyphel
18th April 2007, 10:29
Thanks for the tip Wysota, but I'll stay on my showEvent solution. I'm not sure about that the sizeHint will works correctly... Resize should work too, but it doesn't :(