Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Closing QMdiSubWindow From Within Widget
Forum Updated to NodeBB v4.3 + New Features

Closing QMdiSubWindow From Within Widget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joeuser
    wrote on last edited by
    #1

    Anybody know the proper way to close a QMdiSubWindow programmatically from within the QWidget it contains? For instance, I have a requirement to put a "Close" button on a form, which when clicked should close the QMdiSubWindow that contains the form. The best solution I've come up with is to set the parent of the form to the QMdiSubWindow and then connect the button's clicked() signal to the close slot of the parentWidget. Such as:

    @
    QMdiSubWindow* sw = new QMdiSubWindow( mdiArea );
    sw->setWidget( new MyForm( sw ) );
    sw->setAttribute( Qt::WA_DeleteOnClose );
    mdiArea->addSubWindow( sw );
    sw->show();
    @

    Then within MyForm constructor I would connect the signal:

    @
    connect( closeButton, SIGNAL( clicked() ),
    parentWidget(), SLOT( close() ) );
    @

    This approach only works if MyForm's parentWidget is the QMdiSubWindow. I can't help thinking there must be a better way. Seems like there should be some kind of property or attribute on QMdiSubWindow like "close me when widget closes" but I haven't found it. Anyone have any ideas?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Looks ok to me. The way you do it is actually one of the two that the Qt documentation mentions.

      I'm not aware of an easier way to achieve this.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        joeuser
        wrote on last edited by
        #3

        Thanks for the feedback, I kept thinking I was missing something. I couldn't find anything in the Qt docs about this kind of thing. What documentation mentions this way and what is the other way?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          It's in the docs of "QMdiArea::addSubWindow() ":http://doc.qt.nokia.com/4.7/qmdiarea.html#addSubWindow

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved