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

在使用QFileDialog打开文件对话框时,如何设定默认显示的文件过滤器?当按字母顺序排列过滤器时,默认选中变为'所有文件',但实际需求是保持'JPEG'为默认。解决方法是通过传递一个额外的QString参数来指定默认过滤器,例如:`QString selfilter = tr("JPEG (*.jpg *.jpeg)");`然后在getOpenFileName函数中使用这个selfilter变量。
摘要由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、付费专栏及课程。

余额充值