View Full Version : QApplication::processEvents lets me to run all pending commands for my widget?

18th January 2012, 17:14
I have a custom widget which is created being some parameters.
I have :

A_panel * a_panel = new A_panel(a_widget, parent, sizable );
QApplication::processEvents(QEventLoop::AllEvents) ;
a_panel->resize(parent->width()*float(tam_100_or_0)/100, parent->height()*float(tam_100_or_0)/100);

Ok. my 'A_panel' has three internal calls. The constructor calls a function and this one a last one, that sets a 'i_am_ready' variable to 'true'.
the resizeevent has 'if i_am_ready!=true return', that is, until my widget is not ready I dont want to process any resize event.

Ok. The last code fails, I have a resizeevent before the three functions be called.
I have tried to use the processEvents, but without success.
Any help or idea ? Thanks.

18th January 2012, 18:15
What is this processEvents() call of yours supposed to do? Returning from resizeEvent() doesn't cause your widget to prevent being resized. resizeEvent() is simply a notification for the application that the widget has been resized. As far as I know you can't prevent the resize itself even if you explicitly ignore() the event.

18th January 2012, 18:34
Sorry. I explain me just a little...
I have a code to place some internal widgets and paint the widget. I call it from resizeevent if 'i_am_ready' is true.
What I want to do is a way to be sure all my internal code was executed before continue.
(My constructor calls three functions before it was ready )

This is the reason to try 'processevents'. (not to avoid resizeevent).
Thanks wy.

18th January 2012, 19:12
But what events do you expect your widget to process right after the constructor returns? Are you posting any events to the widget in the constructor?

18th January 2012, 19:56
You are going to send me to the .... excuse me for not explaining better.

This is the psedo-code I have :

A_panel() // constructor type 1
{ call generic_constructor}
A_panel() // constructor type 2
{ call generic_constructor}

generic_constructor() {
set some variables;
launch a timer of 1 milisecond interval to check if the parent_widget is already visible.it calls timer_slot_function
the timer_slot_function () {
if (my_parent_visible) place_things() ;

place_things() {
I measure the size and other things of widget parent to set the size and position of this custom_widget
i_am_ready=true; // finally I set 'i_am_ready' to true.

resize_event() {
if (i_am_ready) place_things }

Due to some reasons I dont want to execute 'place_things' on undesirable resize_events . I control this using 'i_am_ready' variable.

I have this code :(a_panel is the custom widget)

A_panel * a_panel = new A_panel(a_widget, parent, sizable );

a_panel->resize(parent->width()*float(tam_100_or_0)/100, parent->height()*float(tam_100_or_0)/100);

And I discover I have a resize_event (showed by the qdebug) before all the last code is executed.
( that is: genericcontructor-timer-placethings).

Ok, this is due to the timer... i know.

I have just found that the problem is the timer i use...
Sorry again .

18th January 2012, 20:18
How about this:

class MyWidget : public QWidget {
MyWidget(QWidget *parent = 0) : QWidget(parent) {
m_initialized = false;
void placeThings() { ... }
void showEvent(QShowEvent *se) {
if(!m_initialized) {
m_initialized = true;
bool m_initialized;

18th January 2012, 20:21
I'm going to consider it. I'm sorry but I have to say you something on friday...
Thanks again.