简体   繁体   English

PyQt:QFileDialog打开后直接关闭

[英]PyQt: QFileDialog close directly after opening

I am using QFileDialog (both getOpenFileName and getSaveFileName ) but have a strange behavior: 我正在使用QFileDialoggetOpenFileNamegetSaveFileName ),但是有一个奇怪的行为:

  • if I call them directly from a (ipython) shell, I have no problem 如果我直接从(ipython)shell调用它们,我没有问题
  • if I call them from a widget: 如果我从小部件中调用它们:
    • in mac 10.6, it closes the dialog just after opening it (the dialog "pop" then close) 在Mac 10.6中,打开对话框后即关闭对话框(对话框“ pop”然后关闭)
    • in mac 10.6, it works fine if I use the QtGui.QFileDialog.DontUseNativeDialog 在Mac 10.6中,如果我使用QtGui.QFileDialog.DontUseNativeDialog ,它将正常工作
    • in win xp (in a virtualbox) it works without the DontUseNativeDialog option 在win xp(在virtualbox中)中,无需DontUseNativeDialog选项即可使用
    • in win xp, with the DontUseNativeDialog option, the dialog close right after opening 在win xp中,使用DontUseNativeDialog选项,对话框在打开后立即关闭
    • in win 7, both seems to work (someone else did the test, so I did not see it my-self) 在胜利7中,两者似乎都起作用(其他人进行了测试,所以我自己没有看到它)

My questions: 我的问题:

  • what would be the reasons for the dialog to close right after opening, in general? 通常,打开对话框后立即关闭对话框的原因是什么?
  • why would it do that in some cases but not all? 为什么在某些情况下而不是全部都这样做?
  • how should I do to make it work cross-platform? 如何使它跨平台工作?

I found out that this problem comes from a strange conflict with ipython and its --pylab start option. 我发现此问题来自与ipython及其--pylab start选项的奇怪冲突。 It can thus be avoided by either 因此可以避免

  • executing the code directly using python xxxx.py 直接使用python xxxx.py执行代码
  • or by not using the pylab option 或不使用pylab选项

In both cases, the qapplication should be started manually: 在这两种情况下,都应手动启动qapplication:

qapp = QtGui.QApplication([])
my_app = MyQtAppWindow(...)
my_app.exec_()

However, I still don't know why there is a conflict. 但是,我仍然不知道为什么会发生冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM