[英]QFileDialog: add suffix after selecting file
I need to add suffix to selected filename in QFileDialog
with QFileDialog::AcceptSave
accept mode. 我需要在QFileDialog
使用QFileDialog::AcceptSave
接受模式为所选文件名添加后缀。 For example, after selecting "1.txt" file in QFileDialog edit should be select "1_suffix.txt". 例如,在QFileDialog中选择“1.txt”文件后,编辑应选择“1_suffix.txt”。 It should be added before file accepting, because I need the user to have the ability to change the filename before applying file. 它应该在文件接受之前添加,因为我需要用户能够在应用文件之前更改文件名。
code: 码:
m_dialog.setAcceptMode(QFileDialog::AcceptSave);
m_dialog.setWindowModality(Qt::WindowModal);
m_dialog.setFileMode(QFileDialog::AnyFile);
m_dialog.setDefaultSuffix("_suffix");
if(m_dialog.exec() == QFileDialog::Accept)
{
setPath(m_dialog.selectedFiles()[0]);
}
Usually, a QFileDialog
is displaying the platform file dialog. 通常, QFileDialog
正在显示平台文件对话框。 To get the behavior you want, you'd need to use platform-specific mechanisms; 要获得所需的行为,您需要使用特定于平台的机制; Qt doesn't implement such functionality. Qt没有实现这样的功能。
If you're using the non-native file dialog, you could inspect its structure to find the widget(s) you're after, filter relevant events on them, and inject the behavior you need. 如果您正在使用非本机文件对话框,则可以检查其结构以查找您所关注的窗口小部件,过滤相关事件并注入所需的行为。
Try extending QFileDialog and subscribe to QFileDialog signals 尝试扩展QFileDialog并订阅QFileDialog信号
void fileSelected(QString file)
void currentChanged(QString path)
It can be a start. 这可以是一个开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.