qfiledialog文件过滤_如何在QFileDialog上设置选定的过滤器?

在使用QFileDialog时,如何设置默认选中的文件过滤器?通过指定额外的参数可以实现这一目标。例如,可以这样设置:`QString selfilter = tr("JPEG (*.jpg *.jpeg)");`然后在调用`getOpenFileName`时传入该过滤器:`QFileDialog::getOpenFileName(this, title, directory, tr("All files (*.*);;JPEG (*.jpg *.jpeg);;TIFF (*.tif)", &selfilter)`。虽然Qt文档对此描述不清晰,但实践证明这种方法有效。" 120538163,5109599,Redis基础详解:数据类型、持久化与高可用,"['Redis', '数据库', '缓存', '持久化', '高可用性']
摘要由CSDN通过智能技术生成

I have a open file dialog with three filters:

QString fileName = QFileDialog::getOpenFileName(

this,

title,

directory,

tr("JPEG (*.jpg *.jpeg);; TIFF (*.tif);; All files (*.*)")

);

This displays a dialog with "JPEG" selected as the default filter. I wanted to put the filter list in alphabetical order so "All files" was first in the list. If I do this however, "All files" is the default selected filter - which I don't want.

Can I set the default selected filter for this dialog or do I have to go with the first specified filter?

I tried specifying a 5th argument (QString) to set the default selected filter but this didn't work. I think this might only be used to retrieve the filter that was set by the user.

解决方案

Like this:

QString selfilter = tr("JPEG

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值