Here we use the static QFileDialog::getExistingDirectory() function which returns an existing directory selected by the user. The easiest way to create a QFileDialog is to use the convenience static functions. QFileDialog enables a user to traverse the file system in order to select one or many files or a directory. The browse() slot presents a file dialog to the user, using the QFileDialog class. If (director圜omboBox - >findText(directory) = - 1)ĭirector圜omboBox - >setCurrentIndex(director圜omboBox - >findText(directory))
QString directory = QDir ::toNativeSeparators( QFileDialog ::getExistingDirectory( this, tr( "Find Files"), QDir ::currentPath())) We have, however, put the Find and Quit buttons and a stretchable space in a separate QHBoxLayout first, to make the buttons appear in the Window widget's bottom right corner.Īlternatively, we could have used Qt Designer to construct a UI file, and uic to generate this code. We create the widgets to build up the UI, and we add them to a main layout using QGridLayout. MainLayout - >addWidget(findButton, 4, 2) MainLayout - >addWidget(filesFoundLabel, 4, 0, 1, 2)
MainLayout - >addWidget(filesTable, 3, 0, 1, 3) MainLayout - >addWidget(browseButton, 2, 2) MainLayout - >addWidget(director圜omboBox, 2, 1) MainLayout - >addWidget( new QLabel(tr( "In directory:")), 2, 0) MainLayout - >addWidget(textComboBox, 1, 1, 1, 2) MainLayout - >addWidget( new QLabel(tr( "Containing text:")), 1, 0)
MainLayout - >addWidget(fileComboBox, 0, 1, 1, 2) MainLayout - >addWidget( new QLabel(tr( "Named:")), 0, 0) QGridLayout *mainLayout = new QGridLayout( this) QPushButton *browseButton = new QPushButton(tr( "&Browse."), this) Ĭonnect(browseButton, & QAbstractButton ::clicked, this, &Window ::browse) įindButton = new QPushButton(tr( "&Find"), this) Ĭonnect(findButton, & QAbstractButton ::clicked, this, &Window ::find) Ĭonnect(fileComboBox - >lineEdit(), & QLineEdit ::returnPressed, this, &Window ::animateFindClick) Ĭonnect(textComboBox - >lineEdit(), & QLineEdit ::returnPressed, this, &Window ::animateFindClick) ĭirector圜omboBox = createComboBox( QDir ::toNativeSeparators( QDir ::currentPath())) Ĭonnect(director圜omboBox - >lineEdit(), & QLineEdit ::returnPressed, this, &Window ::animateFindClick)