⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qfiledialog.html

📁 QT参考文档
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="getOpenFileNames"></a>QFileDialog::getOpenFileNames ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;filter = QString::null, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;dir = QString::null, <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;caption = QString::null, <a href="qstring.html">QString</a>&nbsp;*&nbsp;selectedFilter = 0, bool&nbsp;resolveSymlinks = TRUE )<tt> [静态]</tt>
</h3>
这是一个返回由用户选择的已经存在的一个或多个文件的方便的静态函数。
<p> <pre>
    <a href="qstringlist.html">QStringList</a> files = QFileDialog::<a href="#getOpenFileNames">getOpenFileNames</a>(
                            "Images (*.png *.xpm *.jpg)",
                            "/home",
                            this,
                            "open files dialog"
                            "Select one or more files to open" );
  </pre>
 
<p> 这个函数创建了一个父对象为<em>parent</em>、名称为<em>name</em>的模式文件对话框。如果父对象不为0,这个对话框将被显示在它的父对象上面的中间。
<p> 文件的工作目录将被设置为<em>dir</em>。如果<em>dir</em>包括一个文件名,这个文件将被选择。过滤器被设置为<em>filter</em>,这样只有匹配过滤器的文件才会被显示。被选择的过滤器被设置为<em>selectedFilter</em>。参数<em>dir</em>、<em>selectedFilter</em>和<em>filter</em>可以为<a href="qstring.html#QString-null">QString::null</a>。
<p> 对话框的标题可以被设置为<em>caption</em>。如果<em>caption</em>没有被指定,那么将会有一个默认标题被使用。
<p> 在Windows和Mac OS X下,这个静态函数将使用本地文件对话框而不是QFileDialog,除非应用程序的风格被设置为本地风格以外的某种风格。
<p> 在Unix/X11下,文件对话框的通常行为是解析并跟踪符号连接。例如,如果/usr/tmp是/var/tmp的符号连接,那么在进入/usr/tmp之后,文件对话框将改变到/var/tmp。如果<em>resolveSymlinks</em>为假,文件对话框将把符号连接看作通常的目录。
<p> 注意如果你想遍历文件的列表,你应该在一个复制上进行遍历,例如:
<pre>
    <a href="qstringlist.html">QStringList</a> list = files;
    QStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
    while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
        myProcessing( *it );
        ++it;
    }
    </pre>
 
<p> <p>也可以参考<a href="#getOpenFileName">getOpenFileName</a>()、<a href="#getSaveFileName">getSaveFileName</a>()和<a href="#getExistingDirectory">getExistingDirectory</a>()。

<h3 class=fn><a href="qstring.html">QString</a> <a name="getSaveFileName"></a>QFileDialog::getSaveFileName ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;startWith = QString::null, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;filter = QString::null, <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;caption = QString::null, <a href="qstring.html">QString</a>&nbsp;*&nbsp;selectedFilter = 0, bool&nbsp;resolveSymlinks = TRUE )<tt> [静态]</tt>
</h3>
这是一个返回由用户选择的已经存在的文件的方便的静态函数。这个文件不一定存在。
<p> 这个函数创建了一个父对象为<em>parent</em>、名称为<em>name</em>的模式文件对话框。如果父对象不为0,这个对话框将被显示在它的父对象上面的中间。
<p> <pre>
    <a href="qstring.html">QString</a> s = QFileDialog::<a href="#getSaveFileName">getSaveFileName</a>(
                    "/home",
                    "Images (*.png *.xpm *.jpg)",
                    this,
                    "save file dialog"
                    "Choose a filename to save under" );
  </pre>
 
<p> 文件的工作目录将被设置为<em>startWith</em>。如果<em>startWith</em>包括一个文件名,这个文件将被选择。过滤器被设置为<em>filter</em>,这样只有匹配过滤器的文件才会被显示。被选择的过滤器被设置为<em>selectedFilter</em>。参数<em>startWith</em>、<em>selectedFilter</em>和<em>filter</em>可以为<a href="qstring.html#QString-null">QString::null</a>。
<p> 对话框的标题可以被设置为<em>caption</em>。如果<em>caption</em>没有被指定,那么将会有一个默认标题被使用。
<p> 在Windows和Mac OS X下,这个静态函数将使用本地文件对话框而不是QFileDialog,除非应用程序的风格被设置为本地风格以外的某种风格。
<p> 在Unix/X11下,文件对话框的通常行为是解析并跟踪符号连接。例如,如果/usr/tmp是/var/tmp的符号连接,那么在进入/usr/tmp之后,文件对话框将改变到/var/tmp。如果<em>resolveSymlinks</em>为假,文件对话框将把符号连接看作通常的目录。
<p> <p>也可以参考<a href="#getOpenFileName">getOpenFileName</a>()、<a href="#getOpenFileNames">getOpenFileNames</a>()和<a href="#getExistingDirectory">getExistingDirectory</a>()。
<p>实例:<a href="qaction-application-example.html#x1069">action/application.cpp</a>、<a href="addressbook-example.html#x517">addressbook/mainwindow.cpp</a>、<a href="simple-application-example.html#x1513">application/application.cpp</a>、<a href="tutorial2-05.html#x2470">chart/chartform.cpp</a>、<a href="qmag-example.html#x1628">qmag/qmag.cpp</a>、<a href="qwerty-example.html#x364">qwerty/qwerty.cpp</a>和<a href="showimg-example.html#x1257">showimg/showimg.cpp</a>。

<h3 class=fn><a href="qfileiconprovider.html">QFileIconProvider</a>&nbsp;* <a name="iconProvider"></a>QFileDialog::iconProvider ()<tt> [静态]</tt>
</h3>
返回在文件对话框上当前设置的图标提供者的指针。默认情况下没有图标提供者,并且这个函数返回0。
<p> <p>也可以参考<a href="#setIconProvider">setIconProvider</a>()和<a href="qfileiconprovider.html">QFileIconProvider</a>。

<h3 class=fn>bool <a name="isContentsPreviewEnabled"></a>QFileDialog::isContentsPreviewEnabled () const
</h3>
<p>如果文件对话框提供当前选择文件的内容预览,返回真,否则返回假。详细情况请参考<a href="qfiledialog.html#contentsPreview-prop">“contentsPreview”</a>属性。

<h3 class=fn>bool <a name="isInfoPreviewEnabled"></a>QFileDialog::isInfoPreviewEnabled () const
</h3>
<p>如果文件对话框提供当前选择文件的信息预览,返回真,否则返回假。详细情况请参考<a href="qfiledialog.html#infoPreview-prop">“infoPreview”</a>属性。

<h3 class=fn><a href="qfiledialog.html#Mode-enum">Mode</a> <a name="mode"></a>QFileDialog::mode () const
</h3>
<p>Returns the file dialog's mode.
See the <a href="qfiledialog.html#mode-prop">"mode"</a> property for details.

<h3 class=fn><a href="qfiledialog.html#PreviewMode-enum">PreviewMode</a> <a name="previewMode"></a>QFileDialog::previewMode () const
</h3>
<p>返回文件对话框的预览模式。详细情况请参考<a href="qfiledialog.html#previewMode-prop">“previewMode”</a>属性。

<h3 class=fn>void <a name="rereadDir"></a>QFileDialog::rereadDir ()
</h3>
重新读取在文件对话框中显示的当前目录。
<p> 只有在如果目录的内容发生改变并且你想刷新文件对话框来反映这样的变化时,你才需要调用这个函数。
<p> <p>也可以参考<a href="#resortDir">resortDir</a>()。

<h3 class=fn>void <a name="resortDir"></a>QFileDialog::resortDir ()
</h3>
重新排列所显示的目录。
<p> <p>也可以参考<a href="#rereadDir">rereadDir</a>()。

<h3 class=fn>void <a name="selectAll"></a>QFileDialog::selectAll ( bool&nbsp;b )
</h3>
如果<em>b</em>为真,那么当前目录下的所有文件都被选择,否则它们都被取消选择。

<h3 class=fn><a href="qstring.html">QString</a> <a name="selectedFile"></a>QFileDialog::selectedFile () const
</h3>
<p>返回被选择文件的名称。详细情况请参考<a href="qfiledialog.html#selectedFile-prop">“selectedFile”</a>属性。

<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="selectedFiles"></a>QFileDialog::selectedFiles () const
</h3>
<p>返回被选择文件的列表。详细情况请参考<a href="qfiledialog.html#selectedFiles-prop">“selectedFiles”</a>属性。

<h3 class=fn><a href="qstring.html">QString</a> <a name="selectedFilter"></a>QFileDialog::selectedFilter () const
</h3>
<p>返回文件对话框中用户所选择的过滤器。详细情况请参考<a href="qfiledialog.html#selectedFilter-prop">“selectedFilter”</a>属性。

<h3 class=fn>void <a name="setContentsPreview"></a>QFileDialog::setContentsPreview ( <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;w, <a href="qfilepreview.html">QFilePreview</a>&nbsp;*&nbsp;preview )
</h3>
设置被用于作为文件对话框显示文件内容的窗口部件为<em>w</em>并且使用<a href="qfilepreview.html">QFilePreview</a> <em>preview</em>来预览内容。
<p> 通常你需要创建一个继承<a href="qwidget.html">QWidget</a>和QFilePreview的预览窗口部件,所以你需要传递同一个窗口部件两次。
<p> <pre>
    class Preview : public <a href="qlabel.html">QLabel</a>, public QFilePreview
    {
    public:
        Preview( <a href="qwidget.html">QWidget</a> *parent=0 ) : <a href="qlabel.html">QLabel</a>( parent ) {}

        void previewUrl( const <a href="qurl.html">QUrl</a> &amp;u )
        {
            <a href="qstring.html">QString</a> path = u.<a href="qurl.html#path">path</a>();
            <a href="qpixmap.html">QPixmap</a> pix( path );
            if ( pix.<a href="qpixmap.html#isNull">isNull</a>() )
                setText( "This is not a pixmap" );
            else
                setPixmap( pix );
        }
    };

  //...

  int main( int argc, char** argv )
  {
    Preview* p = new Preview;

    QFileDialog* fd = new QFileDialog( this );
    fd-&gt;<a href="#setContentsPreviewEnabled">setContentsPreviewEnabled</a>( TRUE );
    fd-&gt;<a href="#setContentsPreview">setContentsPreview</a>( p, p );
    fd-&gt;<a href="#setPreviewMode">setPreviewMode</a>( QFileDialog::<a href="#PreviewMode-enum">Contents</a> );
    fd-&gt;<a href="qdialog.html#show">show</a>();
  }
  </pre>
 
<p> <p>也可以参考<a href="#contentsPreview-prop">contentsPreview</a>、<a href="#setInfoPreview">setInfoPreview</a>()和<a href="#previewMode-prop">previewMode</a>。
<p>实例:<a href="qdir-example.html#x1810">qdir/qdir.cpp</a>。

<h3 class=fn>void <a name="setContentsPreviewEnabled"></a>QFileDialog::setContentsPreviewEnabled ( bool )
</h3>
<p>设置文件对话框是否提供当前选择文件的内容预览。详细情况请参考<a href="qfiledialog.html#contentsPreview-prop">“contentsPreview”</a>属性。

<h3 class=fn>void <a name="setDir"></a>QFileDialog::setDir ( const&nbsp;<a href="qdir.html">QDir</a>&nbsp;&amp;&nbsp;dir )
</h3>
设置文件对话框的工作目录是<em>dir</em>。
<p>也可以参考<a href="#dir">dir</a>()。

<h3 class=fn>void <a name="setDir-2"></a>QFileDialog::setDir ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;pathstr )<tt> [槽]</tt>
</h3> 
这是一个重载成员函数,提供了方便。它的行为基本上和上面的函数相同。
<p> 设置文件对话框的工作目录是<em>pathstr</em>。
<p> <p>也可以参考<a href="#dir">dir</a>()。

<h3 class=fn>void <a name="setFilter"></a>QFileDialog::setFilter ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;newFilter )<tt> [槽]</tt>
</h3>
<p> 设置文件对话框中使用的过滤器为<em>newFilter</em>。
<p> 如果<em>newFilter</em>中包含一对包含一个或多个<em><b>anything*something</b></em>,由空格或者分号分隔的括号,那么只有其中被括号包含的内容会被作为过滤器。这也就是说下面这些调用方法都是相同的:
<p> <pre>
     fd-&gt;setFilter( "All C++ files (*.cpp *.cc *.C *.cxx *.c++)" );
     fd-&gt;setFilter( "*.cpp *.cc *.C *.cxx *.c++" );
     fd-&gt;setFilter( "All C++ files (*.cpp;*.cc;*.C;*.cxx;*.c++)" );
     fd-&gt;setFilter( "*.cpp;*.cc;*.C;*.cxx;*.c++" );
  </pre>
 
<p> <p>也可以参考<a href="#setFilters">setFilters</a>()。

<h3 class=fn>void <a name="setFilters"></a>QFileDialog::setFilters ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;filters )<tt> [槽]</tt>
</h3>
设置文件对话框中使用的过滤器为<em>filters</em>。过滤器中的每一组必须使用<tt>;;</tt>(<em>两个</em>分号)来分隔。
<p> <pre>
    <a href="qstring.html">QString</a> types("*.png;;*.xpm;;*.jpg");
    QFileDialog fd = new QFileDialog( this );
    fd-&gt;<a href="#setFilters">setFilters</a>( types );
    fd-&gt;<a href="qdialog.html#show">show</a>();
  </pre>
 

<h3 class=fn>void <a name="setFilters-2"></a>QFileDialog::setFilters ( const&nbsp;char&nbsp;**&nbsp;types )<tt> [槽]</tt>
</h3>
这是一个重载成员函数,提供了方便。它的行为基本上和上面的函数相同。
<p> 必须是以结束符结尾的字符串列表。

<h3 class=fn>void <a name="setFilters-3"></a>QFileDialog::setFilters ( const&nbsp;<a href="qstringlist.html">QStringList</a>&nbsp;&amp; )<tt> [槽]</tt>
</h3> 
这是一个重载成员函数,提供了方便。它的行为基本上和上面的函数相同。

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -