QPathEdit
A Qt-Widget to get local file and folder-paths in an optimized and simple way.
Introduction
The QPathEdit class was designed to provide a widget that allows the user to easily enter or select a local file or directory path. The widget comes with a plugin for QtCreator.
Details
The QPathEdit Class
The QPathEdit class provides the following features:
- Appereance: The Edit is composed of a QLineEdit and QToolButton. It uses natives styles. It should look "normal" on any plattform. It provides 3 different styles to allows customisation of the way these components are displayed.
- Dialog: The user will be able to select his path using QFileDialog. The dialog can be customized to a limited amount.
- Validation: The edit automatically validates entered and selected paths and makes shure, that it always returns a valid path to your program.
- Editable: The edit can be editable or readonly. If editable, the validator will mark invalid paths and an auto completer will simplify path entering.
- Completer: The edit uses an auto completer, that uses the underlying file-system to provide paths as autocompletion to make entering paths even easiert. It can be turned on and off.
- QtCreator Plugin: The edit widget comes with an designer-plugin for Qt-Creator, to make it possible to user the pathEdit insider .ui files.
You can check out the documentation by clicking on QPathEdit, or download the files below.
Usage - A simple Example
Since the QPathEdit is just a simple widget, you can use it like any other widget. The following example will create a simple window with the QPathEdit inside. If the user enters a path, the new path will be logged on the console:
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QPathEdit>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window;
QVBoxLayout *layout = new QVBoxLayout(&window);
QPathEdit *edit = new QPathEdit(&window);
layout->addWidget(edit);
window.setLayout(layout);
QObject::connect(edit, &QPathEdit::pathChanged, [](QString path){
qDebug() << path;
});
window.show();
return a.exec();
}
Installing the Plugin
To install the plugin, you need to copy the right file from the designerplugins.zip
zip-package to the QtCreators designer plugin path. There are a number of subfolders for operating systems I've created the plugin for. If yours is not present, you need to compile the plugin yourself. Copy file (for example qpatheditplugin.dll
) into QtCreators path. The default path would be:
- Windows:
<path_to_qt>/Tools/QtCreator/bin/plugins/designer
- OsX:
<qt_creator_bundle>/Contents/PlugIns/designer
- Linux:
<path_to_qt>/Tools/QtCreator/lib/Qt/plugins/designer
After restarting the creator, navigate to the designer and to "Tools > Form Editor > About Qt Designer Plugins". The plugin should appear there. In the editor itself, you can find it inside the "Input Widgets" Section.
For more details, check Adding Qt Designer Plugins.
Documentation
The documentation is available within the releases and on github pages.
The documentation was created using doxygen. It includes an HTML-documentation and Qt-Help files that can be included into QtCreator (QtAssistant) to show F1-Help (See Adding External Documentation for more details).
Download
All downloads are located at github release. The release includes:
- The sourcecode. To use it, simply copy the repository into you application (preferebly by adding it as a git submodule) and add the line
include(./QPathEdit/qpathedit.pri)
to your .pro-file. This way all files and required libraries will automatically be added. - The documentation, if you want to keep it local or add it to QtCreator
- The precompiled QtCreator Plugins, all build with Qt 5.7.1 and working with at least the current version of QtCreator (4.2.0), for:
- Windows
- MacOs
- X11 (Linux, x64 only)
Icons
The edit uses a default icon for joined dialog buttons. The icon was downloaded from http://www.fatcow.com/free-icons.