开发者

QFileDialog used as widget

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 开发者_如何学Goit disappears. It is possible to avoid it?

Should I work with some QDialog::finished() signal or, QDialog::done()?


First, you can get a double-click signal from QTreeView; it's:

void doubleClicked( const QModelIndex & index );

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.


connect(file_dialog, SIGNAL(finished(int)), file_dialog, SLOT(open()));

This seems to work fine. The geometry stays fixed and it remembers the last path allright..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜