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 (*.jpg *.jpeg)");
QString fileName = QFileDialog::getOpenFileName(
this,
title,
directory,
tr("All files (*.*);;JPEG (*.jpg *.jpeg);;TIFF (*.tif)" ),
&selfilter
);
The docs are a bit vague about this, so I found this out via guessing.
这是所有 QT 支持的图像格式的字符串。
"All files (*.*);;BMP (*.bmp);;CUR (*.cur);;GIF (*.gif);;ICNS (*.icns);;ICO (*.ico);;JPEG (*.jpeg);;JPG (*.jpg);;PBM (*.pbm);;PGM (*.pgm);;PNG (*.png);;PPM (*.ppm);;SVG (*.svg);;SVGZ (*.svgz);;TGA (*.tga);;TIF (*.tif);;TIFF (*.tiff);;WBMP (*.wbmp);;WEBP (*.webp);;XBM (*.xbm);;XPM (*.xpm)"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.