Results 1 to 4 of 4

Thread: Can't close a QWidget from itself

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Can't close a QWidget from itself

    I have a floating widget named float_panel; I create it from another Widget currently showed.

    I show it so:
    Qt Code:
    1. my_float_panel = new Ui_float_panel(this);
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. connect(my_float_panel,SIGNAL(destroyed()),this, SLOT(float_panel_has_closed()));
    To copy to clipboard, switch view to plain text mode 
    But without success.

    Any idea what I'm doing bad ? Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't close a QWidget from itself

    Yes, you can. No idea what you are doing bad, show the code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't close a QWidget from itself

    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 :
    Qt Code:
    1. flags = Qt::SplashScreen;
    2. this->parentWidget()->setWindowFlags(flags);
    To copy to clipboard, switch view to plain text mode 
    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:

    Qt Code:
    1. ui->a_panel_flot_mod->w_add_button("close",WW::icon_close, this, SLOT(w_close_panel()));
    To copy to clipboard, switch view to plain text mode 
    Inside QWidgetB::w_close_panel() I have
    Qt Code:
    1. this->close();
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by tonnot; 25th August 2011 at 10:09.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Can't close a QWidget from itself

    For this:
    Qt Code:
    1. connect(my_float_panel,SIGNAL(destroyed()),this, SLOT(float_panel_has_closed()));
    To copy to clipboard, switch view to plain text mode 
    to work,
    Qt Code:
    1. setAttribute(Qt::WA_DeleteOnClose);
    To copy to clipboard, switch view to plain text mode 
    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. midi child does not close when I call close()
    By qlands in forum Qt Programming
    Replies: 7
    Last Post: 29th July 2011, 22:25
  2. QT application not close after close the mainwindow
    By artome in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 22:23
  3. Replies: 2
    Last Post: 6th May 2011, 08:02
  4. Replies: 2
    Last Post: 17th December 2010, 19:01
  5. QWidget (Qt::Popup), Signal when close or lost focus
    By Tondog in forum Qt Programming
    Replies: 1
    Last Post: 23rd April 2010, 08:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.