[Interest] Calling QMainWindow::close() vs. clicking on close button in title bar

Andy asmaloney at gmail.com
Tue Oct 30 13:53:17 CET 2018


Turns out that if you have a QMainWindow containing a QWindow (e.g. by
using QWidget::createWindowContainer()):

  - if you call QMainWindow::close(), the QWindow receives QEvent::Hide and
does the right thing
  - if you click the close button in the title bar, the QWindow receives
QEvent::Close which calls QWindow::destroy()

This is not what I would expect. Is this by design?

The QWidget::createWindowContainer docs don't mention this as a limitation.

I haven't yet found a way around it, so suggestions appreciated.

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney <https://twitter.com/asmaloney>


On Tue, Oct 30, 2018 at 7:24 AM Andy <asmaloney at gmail.com> wrote:

> *Setup:*
>
> - two QMainWindows - "main" and "viewer"
> - "viewer" uses Qt3D via QWidget::createWindowContainer()
> - shortcut "cmd-w" (Qt::ApplicationShortcut) set up to call close() on
> "viewer" if it is the activeWindow()
> - "viewer" does not have WA_DeleteOnClose set, so the window is only hidden
>
> *Problem:*
>
> - if I close the viewer via the shortcut and reopen it, the 3D view is fine
> - if I close it via the close button in the title bar (macOS or Windows)
> and reopen it, the 3D view is blank
>
> Any idea why my 3D view is getting killed in the second case?
>
> This may be a red-herring, but I've traced both through to
> QWidgetPrivate::close_helper() and each is called with a different mode.
> The first is called with "CloseWithEvent" and the second with
> "CloseWithSpontaneousEvent". Could this be a factor?
>
> I have another window which uses a QGraphicsView set up exactly the same
> way and it works fine, so maybe Qt3D is doing something I'm not expecting
> based on a CloseWithSpontaneousEvent?
>
> Thanks for any ideas/suggestions.
>
> ---
> Andy Maloney  //  https://asmaloney.com
> twitter ~ @asmaloney <https://twitter.com/asmaloney>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181030/1667466e/attachment.html>


More information about the Interest mailing list