QFileDialog 用作小部件
我的目标是:用户可以选择文件(仅*mp3),单击两次后应该播放(因此文件的 QString 应发送到 play() 函数) 首先我开始使用 QTreeView,但是当选择文件时它有信号。
所以我决定创建 QFileDialog 并将其用作 MainWindow 中内置的小部件。 我遇到的唯一问题是双击后它消失了。有可能避免吗?
我应该使用一些 QDialog::finished() 信号还是 QDialog::done() ?
My goal is: user can choose file (only *mp3) and after clicking twice on it it should play (so the QString to file should be send to play() function)
Firstly I started to work with QTreeView, but it has signal when the file is selected.
So I decided to create QFileDialog and used it as widget built-in into MainWindow.
The only problem that I have, that after double-click it disappears. It is possible to avoid it?
Should I work with some QDialog::finished() signal or, QDialog::done()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,可以从QTreeView中获取双击信号;它是:
其次,如果您确实想以这种方式使用 QFileDialog,请首先重写 closeEvent( QCloseEvent * event)。在里面,如果你想关闭对话框,请执行 event->accept(); ,否则只需执行 event->ignore(); 。连接到 QFileDialog::currentChanged( const QString & path );用户双击即可获取文件名。最后一件事——确保在堆上(使用 new)而不是在堆栈上(本地)创建 QFileDialog,并在其上调用 show() 而不是 exec()。
请记住,您可以为其提供父项(this),并且以后不需要删除它。
First, you can get a double-click signal from QTreeView; it's:
Second, if you really want to use the QFileDialog that way, first override closeEvent( QCloseEvent * event). Inside, if you want to close the dialog, do event->accept();, otherwise just do event->ignore();. Connect to QFileDialog::currentChanged( const QString & path ); to get the filename the user double-clicks. One last thing--be sure to create the QFileDialog on the heap (using new), not on the stack (a local), and call show() on it instead of exec().
Remember that you can supply it with a parent (this) and you won't need to delete it later.
这似乎工作正常。几何形状保持固定,并且它会记住最后的路径。
This seems to work fine. The geometry stays fixed and it remembers the last path allright..