PDA

View Full Version : Can't close a QWidget from itself



tonnot
25th August 2011, 09:11
I have a floating widget named float_panel; I create it from another Widget currently showed.

I show it so:

my_float_panel = new Ui_float_panel(this);

Ok, this float_panel has a button to close the Qwidget float_panel instance itself.
Inside the click_event of this button can I simply do: this->close() ?
(Now, I see (because I have a q_debug msg) I am inside the click_event, where I execute this->close(), but my widget remains visible .... )

Also I have tried to connect

connect(my_float_panel,SIGNAL(destroyed()),this, SLOT(float_panel_has_closed()));
But without success.

Any idea what I'm doing bad ? Thanks.

wysota
25th August 2011, 09:15
Yes, you can. No idea what you are doing bad, show the code.

tonnot
25th August 2011, 10:45
The code ....
I cant show the real code, the constructor builds a lot of things. I show you the skeleton. I hope it will help. I tell you all the proccess, in case of it be interesting.


Qwidget_A, is currently showed:
I have a Qpushbutton to load QWidgetB.
And QwidgetB has inside it a 'float_widget', placed with Designer.
>>a_float_widget is a simple widget, but with the capability of be moved,and/or to move severally its parent.

Ok, I put some elements from QwidgetB inside the float_widget. Hide the other elements, adjust the size of float_widget and finally adjust the size of Qwidget B it self. Inside float_widget I have :

flags = Qt::SplashScreen;
this->parentWidget()->setWindowFlags(flags);

Ok, All works fine. I can move the 'window' using the float_panel (itself moves its parent). (Yes, I could to do this reversed, create a_panel and place inside it the widgetB, but I prefere to control QWidgetB ).

Ok, I have for this float_widget a method to create and insert generic custom buttons. (another custom widget with subclased paintevent and mouseevents. )

So, I have inside QWidgetB constructor:


ui->a_panel_flot_mod->w_add_button("close",WW::icon_close, this, SLOT(w_close_panel()));

Inside QWidgetB::w_close_panel() I have

this->close();

When I press the 'button', the Q_WidgetB::w_close_panel() is right called. But everything (the float_widget and the QwidgetB ) remains being visible.

Maybe I have to close another elements before the main ?
What about disconnect ? Have I to disconnect things ?

I hope do you understand what I have described
Thanks

high_flyer
25th August 2011, 11:19
For this:

connect(my_float_panel,SIGNAL(destroyed()),this, SLOT(float_panel_has_closed()));
to work,

setAttribute(Qt::WA_DeleteOnClose);
has to be called.
Otherwise it only gets hidden.

One reason why its not being closed might be, that you are holding the the event loop.
Are you?
close() prompts an event, it doesn't close the widget imminently, the widget will be closed only when the event gets processed.