Discussion:
[Interest] Calling QMainWindow::close() vs. clicking on close button in title bar
Andy
2018-10-30 11:24:59 UTC
Permalink
*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>
Andy
2018-10-30 12:53:17 UTC
Permalink
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
Post by Andy
*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
John Weeks
2018-10-30 19:14:25 UTC
Permalink
Our application needs to control how windows close pretty carefully- we handle QEvent::close by ignoring it, then doing whatever we feel like we need to do. That is, we take over management of the situation.

-John Weeks
WaveMetrics, Inc.
- 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
- 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
- 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
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
-John
Andy
2018-10-31 18:13:49 UTC
Permalink
Thanks Giuseppe.

Reported with example code here: https://bugreports.qt.io/browse/QTBUG-71519

I wasn't sure what to use for Components, but my main issue is with Qt3D
not working properly in this context.

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



On Wed, Oct 31, 2018 at 6:03 AM Giuseppe D'Angelo via Interest <
Post by Andy
Post by Andy
Turns out that if you have a QMainWindow containing a QWindow (e.g. by
- 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.
Smells like a bug to me, please report it.
HTH,
--
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Igor Mironchik
2018-10-31 19:30:34 UTC
Permalink
Hi,

I can suggest

void Main3DWindow::closeEvent(QCloseEvent *e)
{
    hide();

    e->ignore();
}
Post by Andy
Thanks Giuseppe.
https://bugreports.qt.io/browse/QTBUG-71519
I wasn't sure what to use for Components, but my main issue is with
Qt3D not working properly in this context.
---
Andy Maloney  // https://asmaloney.com
On Wed, Oct 31, 2018 at 6:03 AM Giuseppe D'Angelo via Interest
Post by Andy
Turns out that if you have a QMainWindow containing a QWindow
(e.g. by
Post by Andy
    - if you call QMainWindow::close(), the QWindow receives
QEvent::Hide
Post by Andy
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.
Smells like a bug to me, please report it.
HTH,
--
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Loading...