简体   繁体   中英

PyQt: QFileDialog close directly after opening

I am using QFileDialog (both getOpenFileName and getSaveFileName ) but have a strange behavior:

  • if I call them directly from a (ipython) shell, I have no problem
  • if I call them from a widget:
    • in mac 10.6, it closes the dialog just after opening it (the dialog "pop" then close)
    • in mac 10.6, it works fine if I use the QtGui.QFileDialog.DontUseNativeDialog
    • in win xp (in a virtualbox) it works without the DontUseNativeDialog option
    • in win xp, with the DontUseNativeDialog option, the dialog close right after opening
    • in win 7, both seems to work (someone else did the test, so I did not see it my-self)

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. It can thus be avoided by either

  • executing the code directly using python xxxx.py
  • or by not using the pylab option

In both cases, the qapplication should be started manually:

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

However, I still don't know why there is a conflict.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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