1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
|
'\" t
.TH QFileDialog 3qt "21 January 2005" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QFileDialog \- Dialogs that allow users to select files or directories
.SH SYNOPSIS
\fC#include <qfiledialog.h>\fR
.PP
Inherits QDialog.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQFileDialog\fR ( const QString & dirName, const QString & filter = QString::null, QWidget * parent = 0, const char * name = 0, bool modal = FALSE )"
.br
.ti -1c
.BI "\fBQFileDialog\fR ( QWidget * parent = 0, const char * name = 0, bool modal = FALSE )"
.br
.ti -1c
.BI "\fB~QFileDialog\fR ()"
.br
.ti -1c
.BI "QString \fBselectedFile\fR () const"
.br
.ti -1c
.BI "QString \fBselectedFilter\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetSelectedFilter\fR ( const QString & mask )"
.br
.ti -1c
.BI "virtual void \fBsetSelectedFilter\fR ( int n )"
.br
.ti -1c
.BI "void \fBsetSelection\fR ( const QString & filename )"
.br
.ti -1c
.BI "void \fBselectAll\fR ( bool b )"
.br
.ti -1c
.BI "QStringList \fBselectedFiles\fR () const"
.br
.ti -1c
.BI "QString \fBdirPath\fR () const"
.br
.ti -1c
.BI "void \fBsetDir\fR ( const QDir & dir )"
.br
.ti -1c
.BI "const QDir * \fBdir\fR () const"
.br
.ti -1c
.BI "void \fBsetShowHiddenFiles\fR ( bool s )"
.br
.ti -1c
.BI "bool \fBshowHiddenFiles\fR () const"
.br
.ti -1c
.BI "void \fBrereadDir\fR ()"
.br
.ti -1c
.BI "void \fBresortDir\fR ()"
.br
.ti -1c
.BI "enum \fBMode\fR { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly }"
.br
.ti -1c
.BI "void \fBsetMode\fR ( Mode )"
.br
.ti -1c
.BI "Mode \fBmode\fR () const"
.br
.ti -1c
.BI "enum \fBViewMode\fR { Detail, List }"
.br
.ti -1c
.BI "enum \fBPreviewMode\fR { NoPreview, Contents, Info }"
.br
.ti -1c
.BI "void \fBsetViewMode\fR ( ViewMode m )"
.br
.ti -1c
.BI "ViewMode \fBviewMode\fR () const"
.br
.ti -1c
.BI "void \fBsetPreviewMode\fR ( PreviewMode m )"
.br
.ti -1c
.BI "PreviewMode \fBpreviewMode\fR () const"
.br
.ti -1c
.BI "bool \fBisInfoPreviewEnabled\fR () const"
.br
.ti -1c
.BI "bool \fBisContentsPreviewEnabled\fR () const"
.br
.ti -1c
.BI "void \fBsetInfoPreviewEnabled\fR ( bool )"
.br
.ti -1c
.BI "void \fBsetContentsPreviewEnabled\fR ( bool )"
.br
.ti -1c
.BI "void \fBsetInfoPreview\fR ( QWidget * w, QFilePreview * preview )"
.br
.ti -1c
.BI "void \fBsetContentsPreview\fR ( QWidget * w, QFilePreview * preview )"
.br
.ti -1c
.BI "QUrl \fBurl\fR () const"
.br
.ti -1c
.BI "void \fBaddFilter\fR ( const QString & filter )"
.br
.in -1c
.SS "Public Slots"
.in +1c
.ti -1c
.BI "void \fBsetDir\fR ( const QString & pathstr )"
.br
.ti -1c
.BI "void \fBsetUrl\fR ( const QUrlOperator & url )"
.br
.ti -1c
.BI "void \fBsetFilter\fR ( const QString & newFilter )"
.br
.ti -1c
.BI "void \fBsetFilters\fR ( const QString & filters )"
.br
.ti -1c
.BI "void \fBsetFilters\fR ( const char ** types )"
.br
.ti -1c
.BI "void \fBsetFilters\fR ( const QStringList & )"
.br
.in -1c
.SS "Signals"
.in +1c
.ti -1c
.BI "void \fBfileHighlighted\fR ( const QString & )"
.br
.ti -1c
.BI "void \fBfileSelected\fR ( const QString & )"
.br
.ti -1c
.BI "void \fBfilesSelected\fR ( const QStringList & )"
.br
.ti -1c
.BI "void \fBdirEntered\fR ( const QString & )"
.br
.ti -1c
.BI "void \fBfilterSelected\fR ( const QString & )"
.br
.in -1c
.SS "Static Public Members"
.in +1c
.ti -1c
.BI "QString \fBgetOpenFileName\fR ( const QString & startWith = QString::null, const QString & filter = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, QString * selectedFilter = 0, bool resolveSymlinks = TRUE )"
.br
.ti -1c
.BI "QString \fBgetSaveFileName\fR ( const QString & startWith = QString::null, const QString & filter = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, QString * selectedFilter = 0, bool resolveSymlinks = TRUE )"
.br
.ti -1c
.BI "QString \fBgetExistingDirectory\fR ( const QString & dir = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, bool dirOnly = TRUE, bool resolveSymlinks = TRUE )"
.br
.ti -1c
.BI "QStringList \fBgetOpenFileNames\fR ( const QString & filter = QString::null, const QString & dir = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, QString * selectedFilter = 0, bool resolveSymlinks = TRUE )"
.br
.ti -1c
.BI "void \fBsetIconProvider\fR ( QFileIconProvider * provider )"
.br
.ti -1c
.BI "QFileIconProvider * \fBiconProvider\fR ()"
.br
.in -1c
.SS "Properties"
.in +1c
.ti -1c
.BI "bool \fBcontentsPreview\fR - whether the file dialog can provide a contents preview of the currently selected file"
.br
.ti -1c
.BI "QString \fBdirPath\fR - the file dialog's working directory \fI(read " "only" ")\fR"
.br
.ti -1c
.BI "bool \fBinfoPreview\fR - whether the file dialog can provide preview information about the currently selected file"
.br
.ti -1c
.BI "Mode \fBmode\fR - the file dialog's mode"
.br
.ti -1c
.BI "PreviewMode \fBpreviewMode\fR - the preview mode for the file dialog"
.br
.ti -1c
.BI "QString \fBselectedFile\fR - the name of the selected file \fI(read " "only" ")\fR"
.br
.ti -1c
.BI "QStringList \fBselectedFiles\fR - the list of selected files \fI(read " "only" ")\fR"
.br
.ti -1c
.BI "QString \fBselectedFilter\fR - the filter which the user has selected in the file dialog \fI(read " "only" ")\fR"
.br
.ti -1c
.BI "bool \fBshowHiddenFiles\fR - whether hidden files are shown in the file dialog"
.br
.ti -1c
.BI "ViewMode \fBviewMode\fR - the file dialog's view mode"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "void \fBaddWidgets\fR ( QLabel * l, QWidget * w, QPushButton * b )"
.br
.ti -1c
.BI "void \fBaddToolButton\fR ( QButton * b, bool separator = FALSE )"
.br
.ti -1c
.BI "void \fBaddLeftWidget\fR ( QWidget * w )"
.br
.ti -1c
.BI "void \fBaddRightWidget\fR ( QWidget * w )"
.br
.in -1c
.SH DESCRIPTION
The QFileDialog class provides dialogs that allow users to select files or directories.
.PP
The QFileDialog class enables a user to traverse their file system in order to select one or many files or a directory.
.PP
The easiest way to create a QFileDialog is to use the static functions. On Windows, these static functions will call the native Windows file dialog and on Mac OS X, these static function will call the native Mac OS X file dialog.
.PP
.nf
.br
QString s = QFileDialog::getOpenFileName(
.br
"/home",
.br
"Images (*.png *.xpm *.jpg)",
.br
this,
.br
"open file dialog",
.br
"Choose a file" );
.br
.fi
.PP
In the above example, a modal QFileDialog is created using a static function. The startup directory is set to "/home". The file filter is set to "Images (*.png *.xpm *.jpg)". The parent of the file dialog is set to \fIthis\fR and it is given the identification name - "open file dialog". The caption at the top of file dialog is set to "Choose a file". If you want to use multiple filters, separate each one with \fItwo\fR semi-colons, e.g.
.PP
.nf
.br
"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
.br
.fi
.PP
You can create your own QFileDialog without using the static functions. By calling setMode(), you can set what can be returned by the QFileDialog.
.PP
.nf
.br
QFileDialog* fd = new QFileDialog( this, "file dialog", TRUE );
.br
fd->setMode( QFileDialog::AnyFile );
.br
.fi
.PP
In the above example, the mode of the file dialog is set to AnyFile, meaning that the user can select any file, or even specify a file that doesn't exist. This mode is useful for creating a "File Save As" file dialog. Use ExistingFile if the user must select an existing file or Directory if only a directory may be selected. (See the QFileDialog::Mode enum for the complete list of modes.)
.PP
You can retrieve the dialog's mode with mode(). Use setFilter() to set the dialog's file filter, e.g.
.PP
.nf
.br
fd->setFilter( "Images (*.png *.xpm *.jpg)" );
.br
.fi
.PP
In the above example, the filter is set to "Images (*.png *.xpm *.jpg)", this means that only files with the extension \fCpng\fR, \fCxpm\fR or \fCjpg\fR will be shown in the QFileDialog. You can apply several filters by using setFilters() and add additional filters with addFilter(). Use setSelectedFilter() to select one of the filters you've given as the file dialog's default filter. Whenever the user changes the filter the filterSelected() signal is emitted.
.PP
The file dialog has two view modes, QFileDialog::List which simply lists file and directory names and QFileDialog::Detail which displays additional information alongside each name, e.g. file size, modification date, etc. Set the mode with setViewMode().
.PP
.nf
.br
fd->setViewMode( QFileDialog::Detail );
.br
.fi
.PP
The last important function you will need to use when creating your own file dialog is selectedFile().
.PP
.nf
.br
QString fileName;
.br
if ( fd->exec() == QDialog::Accepted )
.br
fileName = fd->selectedFile();
.br
.fi
.PP
In the above example, a modal file dialog is created and shown. If the user clicked OK, then the file they selected is put in \fCfileName\fR.
.PP
If you are using the ExistingFiles mode then you will need to use selectedFiles() which will return the selected files in a QStringList.
.PP
The dialog's working directory can be set with setDir(). The display of hidden files is controlled with setShowHiddenFiles(). The dialog can be forced to re-read the directory with rereadDir() and re-sort the directory with resortDir(). All the files in the current directory can be selected with selectAll().
.SH "Creating and using preview widgets"
There are two kinds of preview widgets that can be used with QFileDialogs: \fIcontent\fR preview widgets and \fIinformation\fR preview widgets. They are created and used in the same way except that the function names differ, e.g. setContentsPreview() and setInfoPreview().
.PP
A preview widget is a widget that is placed inside a QFileDialog so that the user can see either the contents of the file, or information about the file.
.PP
.nf
.br
class Preview : public QLabel, public QFilePreview
.br
{
.br
public:
.br
Preview( QWidget *parent=0 ) : QLabel( parent ) {}
.br
.br
void previewUrl( const QUrl &u )
.br
{
.br
QString path = u.path();
.br
QPixmap pix( path );
.br
if ( pix.isNull() )
.br
setText( "This is not a pixmap" );
.br
else
.br
setPixmap( pix );
.br
}
.br
};
.br
.fi
.PP
In the above snippet, we create a preview widget which inherits from QLabel and QFilePreview. File preview widgets \fImust\fR inherit from QFilePreview.
.PP
Inside the class we reimplement QFilePreview::previewUrl(), this is where we determine what happens when a file is selected. In the above example we only show a preview of the file if it is a valid pixmap. Here's how to make a file dialog use a preview widget:
.PP
.nf
.br
Preview* p = new Preview;
.br
.br
QFileDialog* fd = new QFileDialog( this );
.br
fd->setContentsPreviewEnabled( TRUE );
.br
fd->setContentsPreview( p, p );
.br
fd->setPreviewMode( QFileDialog::Contents );
.br
fd->show();
.br
.fi
.PP
The first line creates an instance of our preview widget. We then create our file dialog and call setContentsPreviewEnabled( TRUE ), this tell the file dialog to preview the contents of the currently selected file. We then call setContentsPreview() -- note that we pass the same preview widget twice. Finally, before showing the file dialog, we call setPreviewMode() setting the mode to \fIContents\fR which will show the contents preview of the file that the user has selected.
.PP
If you create another preview widget that is used for displaying information about a file, create it in the same way as the contents preview widget and call setInfoPreviewEnabled(), and setInfoPreview(). Then the user will be able to switch between the two preview modes.
.PP
For more information about creating a QFilePreview widget see QFilePreview.
.PP
.ce 1
.B "[Image Omitted]"
.PP
.ce 1
.B "[Image Omitted]"
.PP
See also Dialog Classes.
.SS "Member Type Documentation"
.SH "QFileDialog::Mode"
This enum is used to indicate what the user may select in the file dialog, i.e. what the dialog will return if the user clicks OK.
.TP
\fCQFileDialog::AnyFile\fR - The name of a file, whether it exists or not.
.TP
\fCQFileDialog::ExistingFile\fR - The name of a single existing file.
.TP
\fCQFileDialog::Directory\fR - The name of a directory. Both files and directories are displayed.
.TP
\fCQFileDialog::DirectoryOnly\fR - The name of a directory. The file dialog will only display directories.
.TP
\fCQFileDialog::ExistingFiles\fR - The names of zero or more existing files.
.PP
See setMode().
.SH "QFileDialog::PreviewMode"
This enum describes the preview mode of the file dialog.
.TP
\fCQFileDialog::NoPreview\fR - No preview is shown at all.
.TP
\fCQFileDialog::Contents\fR - Show a preview of the contents of the current file using the contents preview widget.
.TP
\fCQFileDialog::Info\fR - Show information about the current file using the info preview widget.
.PP
See setPreviewMode(), setContentsPreview() and setInfoPreview().
.SH "QFileDialog::ViewMode"
This enum describes the view mode of the file dialog, i.e. what information about each file will be displayed.
.TP
\fCQFileDialog::List\fR - Display file and directory names with icons.
.TP
\fCQFileDialog::Detail\fR - Display file and directory names with icons plus additional information, such as file size and modification date.
.PP
See setViewMode().
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QFileDialog::QFileDialog ( const QString & dirName, const QString & filter = QString::null, QWidget * parent = 0, const char * name = 0, bool modal = FALSE )"
Constructs a file dialog called \fIname\fR with the parent, \fIparent\fR. If \fImodal\fR is TRUE then the file dialog is modal; otherwise it is modeless.
.PP
If \fIdirName\fR is specified then it will be used as the dialog's working directory, i.e. it will be the directory that is shown when the dialog appears. If \fIfilter\fR is specified it will be used as the dialog's file filter.
.SH "QFileDialog::QFileDialog ( QWidget * parent = 0, const char * name = 0, bool modal = FALSE )"
Constructs a file dialog called \fIname\fR, with the parent, \fIparent\fR. If \fImodal\fR is TRUE then the file dialog is modal; otherwise it is modeless.
.SH "QFileDialog::~QFileDialog ()"
Destroys the file dialog.
.SH "void QFileDialog::addFilter ( const QString & filter )"
Adds the filter \fIfilter\fR to the list of filters and makes it the current filter.
.PP
.nf
.br
QFileDialog* fd = new QFileDialog( this );
.br
fd->addFilter( "Images (*.png *.jpg *.xpm)" );
.br
fd->show();
.br
.fi
.PP
In the above example, a file dialog is created, and the file filter "Images (*.png *.jpg *.xpm)" is added and is set as the current filter. The original filter, "All Files (*)", is still available.
.PP
See also setFilter() and setFilters().
.SH "void QFileDialog::addLeftWidget ( QWidget * w )\fC [protected]\fR"
Adds the widget \fIw\fR to the left-hand side of the file dialog.
.PP
See also addRightWidget(), addWidgets(), and addToolButton().
.SH "void QFileDialog::addRightWidget ( QWidget * w )\fC [protected]\fR"
Adds the widget \fIw\fR to the right-hand side of the file dialog.
.PP
See also addLeftWidget(), addWidgets(), and addToolButton().
.SH "void QFileDialog::addToolButton ( QButton * b, bool separator = FALSE )\fC [protected]\fR"
Adds the tool button \fIb\fR to the row of tool buttons at the top of the file dialog. The button is appended to the right of this row. If \fIseparator\fR is TRUE, a small space is inserted between the last button of the row and the new button \fIb\fR.
.PP
See also addWidgets(), addLeftWidget(), and addRightWidget().
.SH "void QFileDialog::addWidgets ( QLabel * l, QWidget * w, QPushButton * b )\fC [protected]\fR"
Adds the specified widgets to the bottom of the file dialog. The label \fIl\fR is placed underneath the "file name" and the "file types" labels. The widget \fIw\fR is placed underneath the file types combobox. The button \fIb\fR is placed underneath the Cancel pushbutton.
.PP
.nf
.br
MyFileDialog::MyFileDialog( QWidget* parent, const char* name ) :
.br
QFileDialog( parent, name )
.br
{
.br
QLabel* label = new QLabel( "Added widgets", this );
.br
QLineEdit* lineedit = new QLineEdit( this );
.br
QPushButton* pushbutton = new QPushButton( this );
.br
.br
addWidgets( label, lineedit, pushbutton );
.br
}
.br
.fi
.PP
If you don't want to have one of the widgets added, pass 0 in that widget's position.
.PP
Every time you call this function, a new row of widgets will be added to the bottom of the file dialog.
.PP
See also addToolButton(), addLeftWidget(), and addRightWidget().
.SH "const QDir * QFileDialog::dir () const"
Returns the current directory shown in the file dialog.
.PP
The ownership of the QDir pointer is transferred to the caller, so it must be deleted by the caller when no longer required.
.PP
See also setDir().
.SH "void QFileDialog::dirEntered ( const QString & )\fC [signal]\fR"
This signal is emitted when the user enters a directory.
.PP
See also dir().
.SH "QString QFileDialog::dirPath () const"
Returns the file dialog's working directory. See the "dirPath" property for details.
.SH "void QFileDialog::fileHighlighted ( const QString & )\fC [signal]\fR"
This signal is emitted when the user highlights a file, i.e. makes it the current file.
.PP
See also fileSelected() and filesSelected().
.SH "void QFileDialog::fileSelected ( const QString & )\fC [signal]\fR"
This signal is emitted when the user selects a file.
.PP
See also filesSelected(), fileHighlighted(), and selectedFile.
.SH "void QFileDialog::filesSelected ( const QStringList & )\fC [signal]\fR"
This signal is emitted when the user selects one or more files in \fIExistingFiles\fR mode.
.PP
See also fileSelected(), fileHighlighted(), and selectedFiles.
.SH "void QFileDialog::filterSelected ( const QString & )\fC [signal]\fR"
This signal is emitted when the user selects a filter.
.PP
See also selectedFilter.
.SH "QString QFileDialog::getExistingDirectory ( const QString & dir = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, bool dirOnly = TRUE, bool resolveSymlinks = TRUE )\fC [static]\fR"
This is a convenience static function that will return an existing directory selected by the user.
.PP
.nf
.br
QString s = QFileDialog::getExistingDirectory(
.br
"/home",
.br
this,
.br
"get existing directory",
.br
"Choose a directory",
.br
TRUE );
.br
.fi
.PP
This function creates a modal file dialog called \fIname\fR, with parent, \fIparent\fR. If parent is not 0, the dialog will be shown centered over the parent.
.PP
The dialog's working directory is set to \fIdir\fR, and the caption is set to \fIcaption\fR. Either of these may be QString::null in which case the current directory and a default caption will be used respectively.
.PP
Note on Windows that if \fIdir\fR is QString::null then the dialog's working directory will be set to the user's My Documents directory.
.PP
If \fIdirOnly\fR is TRUE, then only directories will be shown in the file dialog; otherwise both directories and files will be shown.
.PP
Under Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, the file dialog will change to /var/tmp after entering /usr/tmp. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
.PP
Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog, unless the style of the application is set to something other than the native style. (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar).
.PP
See also getOpenFileName(), getOpenFileNames(), and getSaveFileName().
.SH "QString QFileDialog::getOpenFileName ( const QString & startWith = QString::null, const QString & filter = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, QString * selectedFilter = 0, bool resolveSymlinks = TRUE )\fC [static]\fR"
This is a convenience static function that returns an existing file selected by the user. If the user pressed Cancel, it returns a null string.
.PP
.nf
.br
QString s = QFileDialog::getOpenFileName(
.br
"/home",
.br
"Images (*.png *.xpm *.jpg)",
.br
this,
.br
"open file dialog",
.br
"Choose a file to open" );
.br
.fi
.PP
The function creates a modal file dialog called \fIname\fR, with parent, \fIparent\fR. If a parent is not 0, the dialog will be shown centered over the parent.
.PP
The file dialog's working directory will be set to \fIstartWith\fR. If \fIstartWith\fR includes a file name, the file will be selected. The filter is set to \fIfilter\fR so that only those files which match the filter are shown. The filter selected is set to \fIselectedFilter\fR. The parameters \fIstartWith\fR, \fIselectedFilter\fR and \fIfilter\fR may be QString::null.
.PP
The dialog's caption is set to \fIcaption\fR. If \fIcaption\fR is not specified then a default caption will be used.
.PP
Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog, unless the style of the application is set to something other than the native style (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar).
.PP
Under Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, the file dialog will change to /var/tmp after entering /usr/tmp. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
.PP
See also getOpenFileNames(), getSaveFileName(), and getExistingDirectory().
.PP
Examples:
.)l action/application.cpp, addressbook/mainwindow.cpp, application/application.cpp, distributor/distributor.ui.h, network/ftpclient/ftpmainwindow.ui.h, qwerty/qwerty.cpp, and showimg/showimg.cpp.
.SH "QStringList QFileDialog::getOpenFileNames ( const QString & filter = QString::null, const QString & dir = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, QString * selectedFilter = 0, bool resolveSymlinks = TRUE )\fC [static]\fR"
This is a convenience static function that will return one or more existing files selected by the user.
.PP
.nf
.br
QStringList files = QFileDialog::getOpenFileNames(
.br
"Images (*.png *.xpm *.jpg)",
.br
"/home",
.br
this,
.br
"open files dialog",
.br
"Select one or more files to open" );
.br
.fi
.PP
This function creates a modal file dialog called \fIname\fR, with parent \fIparent\fR. If \fIparent\fR is not 0, the dialog will be shown centered over the parent.
.PP
The file dialog's working directory will be set to \fIdir\fR. If \fIdir\fR includes a file name, the file will be selected. The filter is set to \fIfilter\fR so that only those files which match the filter are shown. The filter selected is set to \fIselectedFilter\fR. The parameters \fIdir\fR, \fIselectedFilter\fR and \fIfilter\fR may be QString::null.
.PP
The dialog's caption is set to \fIcaption\fR. If \fIcaption\fR is not specified then a default caption will be used.
.PP
Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog, unless the style of the application is set to something other than the native style. (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar).
.PP
Under Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, the file dialog will change to /var/tmp after entering /usr/tmp. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
.PP
Note that if you want to iterate over the list of files, you should iterate over a copy, e.g.
.PP
.nf
.br
QStringList list = files;
.br
QStringList::Iterator it = list.begin();
.br
while( it != list.end() ) {
.br
myProcessing( *it );
.br
++it;
.br
}
.br
.fi
.PP
See also getOpenFileName(), getSaveFileName(), and getExistingDirectory().
.SH "QString QFileDialog::getSaveFileName ( const QString & startWith = QString::null, const QString & filter = QString::null, QWidget * parent = 0, const char * name = 0, const QString & caption = QString::null, QString * selectedFilter = 0, bool resolveSymlinks = TRUE )\fC [static]\fR"
This is a convenience static function that will return a file name selected by the user. The file does not have to exist.
.PP
It creates a modal file dialog called \fIname\fR, with parent, \fIparent\fR. If a parent is not 0, the dialog will be shown centered over the parent.
.PP
.nf
.br
QString s = QFileDialog::getSaveFileName(
.br
"/home",
.br
"Images (*.png *.xpm *.jpg)",
.br
this,
.br
"save file dialog",
.br
"Choose a filename to save under" );
.br
.fi
.PP
The file dialog's working directory will be set to \fIstartWith\fR. If \fIstartWith\fR includes a file name, the file will be selected. The filter is set to \fIfilter\fR so that only those files which match the filter are shown. The filter selected is set to \fIselectedFilter\fR. The parameters \fIstartWith\fR, \fIselectedFilter\fR and \fIfilter\fR may be QString::null.
.PP
The dialog's caption is set to \fIcaption\fR. If \fIcaption\fR is not specified then a default caption will be used.
.PP
Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog, unless the style of the application is set to something other than the native style. (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar.
.PP
Under Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if /usr/tmp is a symlink to /var/tmp, the file dialog will change to /var/tmp after entering /usr/tmp. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
.PP
See also getOpenFileName(), getOpenFileNames(), and getExistingDirectory().
.PP
Examples:
.)l action/application.cpp, addressbook/mainwindow.cpp, application/application.cpp, network/ftpclient/ftpmainwindow.ui.h, qmag/qmag.cpp, qwerty/qwerty.cpp, and showimg/showimg.cpp.
.SH "QFileIconProvider * QFileDialog::iconProvider ()\fC [static]\fR"
Returns a pointer to the icon provider currently set on the file dialog. By default there is no icon provider, and this function returns 0.
.PP
See also setIconProvider() and QFileIconProvider.
.SH "bool QFileDialog::isContentsPreviewEnabled () const"
Returns TRUE if the file dialog can provide a contents preview of the currently selected file; otherwise returns FALSE. See the "contentsPreview" property for details.
.SH "bool QFileDialog::isInfoPreviewEnabled () const"
Returns TRUE if the file dialog can provide preview information about the currently selected file; otherwise returns FALSE. See the "infoPreview" property for details.
.SH "Mode QFileDialog::mode () const"
Returns the file dialog's mode. See the "mode" property for details.
.SH "PreviewMode QFileDialog::previewMode () const"
Returns the preview mode for the file dialog. See the "previewMode" property for details.
.SH "void QFileDialog::rereadDir ()"
Rereads the current directory shown in the file dialog.
.PP
The only time you will need to call this function is if the contents of the directory change and you wish to refresh the file dialog to reflect the change.
.PP
See also resortDir().
.SH "void QFileDialog::resortDir ()"
Re-sorts the displayed directory.
.PP
See also rereadDir().
.SH "void QFileDialog::selectAll ( bool b )"
If \fIb\fR is TRUE then all the files in the current directory are selected; otherwise, they are deselected.
.SH "QString QFileDialog::selectedFile () const"
Returns the name of the selected file. See the "selectedFile" property for details.
.SH "QStringList QFileDialog::selectedFiles () const"
Returns the list of selected files. See the "selectedFiles" property for details.
.SH "QString QFileDialog::selectedFilter () const"
Returns the filter which the user has selected in the file dialog. See the "selectedFilter" property for details.
.SH "void QFileDialog::setContentsPreview ( QWidget * w, QFilePreview * preview )"
Sets the widget to be used for displaying the contents of the file to the widget \fIw\fR and a preview of those contents to the QFilePreview \fIpreview\fR.
.PP
Normally you would create a preview widget that derives from both QWidget and QFilePreview, so you should pass the same widget twice.
.PP
.nf
.br
class Preview : public QLabel, public QFilePreview
.br
{
.br
public:
.br
Preview( QWidget *parent=0 ) : QLabel( parent ) {}
.br
.br
void previewUrl( const QUrl &u )
.br
{
.br
QString path = u.path();
.br
QPixmap pix( path );
.br
if ( pix.isNull() )
.br
setText( "This is not a pixmap" );
.br
else
.br
setPixmap( pix );
.br
}
.br
};
.br
.br
//...
.br
.br
int main( int argc, char** argv )
.br
{
.br
Preview* p = new Preview;
.br
.br
QFileDialog* fd = new QFileDialog( this );
.br
fd->setContentsPreviewEnabled( TRUE );
.br
fd->setContentsPreview( p, p );
.br
fd->setPreviewMode( QFileDialog::Contents );
.br
fd->show();
.br
}
.br
.fi
.PP
See also contentsPreview, setInfoPreview(), and previewMode.
.PP
Example: qdir/qdir.cpp.
.SH "void QFileDialog::setContentsPreviewEnabled ( bool )"
Sets whether the file dialog can provide a contents preview of the currently selected file. See the "contentsPreview" property for details.
.SH "void QFileDialog::setDir ( const QDir & dir )"
Sets the file dialog's working directory to \fIdir\fR.
.PP
See also dir().
.SH "void QFileDialog::setDir ( const QString & pathstr )\fC [slot]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the file dialog's working directory to \fIpathstr\fR.
.PP
See also dir().
.SH "void QFileDialog::setFilter ( const QString & newFilter )\fC [slot]\fR"
Sets the filter used in the file dialog to \fInewFilter\fR.
.PP
If \fInewFilter\fR contains a pair of parentheses containing one or more of \fI\fBanything*something\fR\fR separated by spaces or by semi-colons then only the text contained in the parentheses is used as the filter. This means that these calls are all equivalent:
.PP
.nf
.br
fd->setFilter( "All C++ files (*.cpp *.cc *.C *.cxx *.c++)" );
.br
fd->setFilter( "*.cpp *.cc *.C *.cxx *.c++" );
.br
fd->setFilter( "All C++ files (*.cpp;*.cc;*.C;*.cxx;*.c++)" );
.br
fd->setFilter( "*.cpp;*.cc;*.C;*.cxx;*.c++" );
.br
.fi
.PP
See also setFilters().
.SH "void QFileDialog::setFilters ( const QString & filters )\fC [slot]\fR"
Sets the filters used in the file dialog to \fIfilters\fR. Each group of filters must be separated by \fC;;\fR (\fItwo\fR semi-colons).
.PP
.nf
.br
QString types("Image files (*.png *.xpm *.jpg);;"
.br
"Text files (*.txt);;"
.br
"Any files (*)");
.br
QFileDialog fd = new QFileDialog( this );
.br
fd->setFilters( types );
.br
fd->show();
.br
.fi
.SH "void QFileDialog::setFilters ( const char ** types )\fC [slot]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
\fItypes\fR must be a null-terminated list of strings.
.SH "void QFileDialog::setFilters ( const QStringList & )\fC [slot]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.SH "void QFileDialog::setIconProvider ( QFileIconProvider * provider )\fC [static]\fR"
Sets the QFileIconProvider used by the file dialog to \fIprovider\fR.
.PP
The default is that there is no QFileIconProvider and QFileDialog just draws a folder icon next to each directory and nothing next to files.
.PP
See also QFileIconProvider and iconProvider().
.PP
Example: showimg/main.cpp.
.SH "void QFileDialog::setInfoPreview ( QWidget * w, QFilePreview * preview )"
Sets the widget to be used for displaying information about the file to the widget \fIw\fR and a preview of that information to the QFilePreview \fIpreview\fR.
.PP
Normally you would create a preview widget that derives from both QWidget and QFilePreview, so you should pass the same widget twice.
.PP
.nf
.br
class Preview : public QLabel, public QFilePreview
.br
{
.br
public:
.br
Preview( QWidget *parent=0 ) : QLabel( parent ) {}
.br
.br
void previewUrl( const QUrl &u )
.br
{
.br
QString path = u.path();
.br
QPixmap pix( path );
.br
if ( pix.isNull() )
.br
setText( "This is not a pixmap" );
.br
else
.br
setText( "This is a pixmap" );
.br
}
.br
};
.br
.br
//...
.br
.br
int main( int argc, char** argv )
.br
{
.br
Preview* p = new Preview;
.br
.br
QFileDialog* fd = new QFileDialog( this );
.br
fd->setInfoPreviewEnabled( TRUE );
.br
fd->setInfoPreview( p, p );
.br
fd->setPreviewMode( QFileDialog::Info );
.br
fd->show();
.br
}
.br
.br
.fi
.PP
See also setContentsPreview(), infoPreview, and previewMode.
.SH "void QFileDialog::setInfoPreviewEnabled ( bool )"
Sets whether the file dialog can provide preview information about the currently selected file. See the "infoPreview" property for details.
.SH "void QFileDialog::setMode ( Mode )"
Sets the file dialog's mode. See the "mode" property for details.
.SH "void QFileDialog::setPreviewMode ( PreviewMode m )"
Sets the preview mode for the file dialog to \fIm\fR. See the "previewMode" property for details.
.SH "void QFileDialog::setSelectedFilter ( const QString & mask )\fC [virtual]\fR"
Sets the current filter selected in the file dialog to the first one that contains the text \fImask\fR.
.SH "void QFileDialog::setSelectedFilter ( int n )\fC [virtual]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the current filter selected in the file dialog to the \fIn\fR-th filter in the filter list.
.PP
See also filterSelected(), selectedFilter, selectedFiles, and selectedFile.
.SH "void QFileDialog::setSelection ( const QString & filename )"
Sets the default selection to \fIfilename\fR. If \fIfilename\fR is absolute, setDir() is also called to set the file dialog's working directory to the filename's directory.
.PP
Example: qdir/qdir.cpp.
.SH "void QFileDialog::setShowHiddenFiles ( bool s )"
Sets whether hidden files are shown in the file dialog to \fIs\fR. See the "showHiddenFiles" property for details.
.SH "void QFileDialog::setUrl ( const QUrlOperator & url )\fC [slot]\fR"
Sets the file dialog's working directory to the directory specified at \fIurl\fR.
.PP
See also url().
.SH "void QFileDialog::setViewMode ( ViewMode m )"
Sets the file dialog's view mode to \fIm\fR. See the "viewMode" property for details.
.SH "bool QFileDialog::showHiddenFiles () const"
Returns TRUE if hidden files are shown in the file dialog; otherwise returns FALSE. See the "showHiddenFiles" property for details.
.SH "QUrl QFileDialog::url () const"
Returns the URL of the current working directory in the file dialog.
.PP
See also setUrl().
.PP
Example: network/networkprotocol/view.cpp.
.SH "ViewMode QFileDialog::viewMode () const"
Returns the file dialog's view mode. See the "viewMode" property for details.
.SS "Property Documentation"
.SH "bool contentsPreview"
This property holds whether the file dialog can provide a contents preview of the currently selected file.
.PP
The default is FALSE.
.PP
See also setContentsPreview() and infoPreview.
.PP
Set this property's value with setContentsPreviewEnabled() and get this property's value with isContentsPreviewEnabled().
.SH "QString dirPath"
This property holds the file dialog's working directory.
.PP
Get this property's value with dirPath().
.PP
See also dir() and setDir().
.SH "bool infoPreview"
This property holds whether the file dialog can provide preview information about the currently selected file.
.PP
The default is FALSE.
.PP
Set this property's value with setInfoPreviewEnabled() and get this property's value with isInfoPreviewEnabled().
.SH "Mode mode"
This property holds the file dialog's mode.
.PP
The default mode is ExistingFile.
.PP
Set this property's value with setMode() and get this property's value with mode().
.SH "PreviewMode previewMode"
This property holds the preview mode for the file dialog.
.PP
If you set the mode to be a mode other than \fINoPreview\fR, you must use setInfoPreview() or setContentsPreview() to set the dialog's preview widget to your preview widget and enable the preview widget(s) with setInfoPreviewEnabled() or setContentsPreviewEnabled().
.PP
See also infoPreview, contentsPreview, and viewMode.
.PP
Set this property's value with setPreviewMode() and get this property's value with previewMode().
.SH "QString selectedFile"
This property holds the name of the selected file.
.PP
If a file was selected selectedFile contains the file's name including its absolute path; otherwise selectedFile is empty.
.PP
See also QString::isEmpty(), selectedFiles, and selectedFilter.
.PP
Get this property's value with selectedFile().
.SH "QStringList selectedFiles"
This property holds the list of selected files.
.PP
If one or more files are selected, selectedFiles contains their names including their absolute paths. If no files are selected or the mode isn't ExistingFiles selectedFiles is an empty list.
.PP
It is more convenient to use selectedFile() if the mode is ExistingFile, Directory or DirectoryOnly.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
QStringList list = myFileDialog.selectedFiles();
.br
QStringList::Iterator it = list.begin();
.br
while( it != list.end() ) {
.br
myProcessing( *it );
.br
++it;
.br
}
.br
.fi
.PP
See also selectedFile, selectedFilter, and QValueList::empty().
.PP
Get this property's value with selectedFiles().
.SH "QString selectedFilter"
This property holds the filter which the user has selected in the file dialog.
.PP
Get this property's value with selectedFilter().
.PP
See also filterSelected(), selectedFiles, and selectedFile.
.SH "bool showHiddenFiles"
This property holds whether hidden files are shown in the file dialog.
.PP
The default is FALSE, i.e. don't show hidden files.
.PP
Set this property's value with setShowHiddenFiles() and get this property's value with showHiddenFiles().
.SH "ViewMode viewMode"
This property holds the file dialog's view mode.
.PP
If you set the view mode to be \fIDetail\fR (the default), then you will see the file's details, such as the size of the file and the date the file was last modified in addition to the file's name.
.PP
If you set the view mode to be \fIList\fR, then you will just see a list of the files and folders.
.PP
See QFileDialog::ViewMode
.PP
Set this property's value with setViewMode() and get this property's value with viewMode().
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qfiledialog.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qfiledialog.3qt) and the Qt
version (3.3.4).
|