How to create a new window button PySide/PyQt?

后端 未结 2 617
你的背包
你的背包 2021-01-13 18:46

I\'m having problems with a \"New Window\" function in PyQt4/PySide with Python 2.7. I connected a initNewWindow() function, to create a new window, to an actio

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-13 19:21

    When initNewWindow() returns, the window variable is deleted and the window's reference count drops to zero, causing the newly created C++ object to be deleted. This is why your window closes immediately.

    If you want to keep it open, make sure to keep a reference around. The easiest way to do this is to make your new window a child of the calling window, and set its WA_DeleteOnClose widget attribute (see Qt::WidgetAttribute).

提交回复
热议问题