Web Analytics Made Easy - Statcounter
Skip to content

Class SBGWidgetFileSelector#

ClassList > SBGWidgetFileSelector

The SBGWidgetFileSelector class is a convenience widget for specifying a file path - it contains a label, a line edit, and a push button to browse for a file.More...

  • #include "SBGWidgetFileSelector.hpp"

Inherits the following classes: QWidget

Public Slots#

Type Name
slot void onBrowse

Public Signals#

Type Name
signal void pathChanged

Public Functions#

Type Name
SBGWidgetFileSelector (QWidget * parent=nullptr)
Constructs a path selector widget.
QString getDefaultDirectory () const
Returns the default directory of the selector.
QString getFilePath ()
Returns the path.
QString getFilter () const
Returns the filter of the selector.
QString getLabel () const
Returns the label shown in the selector.
void setDefaultDirectory (const QString & dir)
Sets the default directory for the selector that will be used for browse if the file path is not set.
void setFilePath (const QString & path)
Sets the path.
void setFilter (const QString & filter)
Sets the filter for the selector.
void setLabel (const QString & label)
Sets the label shown in the selector.
virtual ~SBGWidgetFileSelector ()
Destructs the path selector widget.

Public Static Functions#

Type Name
bool checkFile (const QString & path, bool askUser)
Check whether the file exists.

Detailed Description#

Short name: SBFileSelector

Public Slots Documentation#

slot onBrowse#

void SBGWidgetFileSelector::onBrowse;

Public Signals Documentation#

signal pathChanged#

void SBGWidgetFileSelector::pathChanged;

Public Functions Documentation#

function SBGWidgetFileSelector#

Constructs a path selector widget.

SBGWidgetFileSelector::SBGWidgetFileSelector (
    QWidget * parent=nullptr
) 

When the user clicks on the browse button of this widget, it internally invokes the SBGWindowDialog::getFileNameFromUser function.

The file dialog's working directory is set to the directory of the file path, if specified, else it is set to the default directory, if specified.

// create the file selector widget
SBFileSelector* fileSelector = new SBFileSelector();
fileSelector->setLabel("Choose input file");
// add the file selector widget into a layout
// ...

You can specify the filter in the same way it is specified in QFileDialog. Only files that match the given filter are shown.

You can provide a single filter, for example:

fileSelector->setFilter("PDB file (*.pdb)");

If you want multiple filters, separate them with ';;', for example:

fileSelector->setFilter("Image files (*.png *.xpm *.jpg);;Text files (*.txt)");

See also: SAMSON::getFileNameFromUser, SAMSON::getFileNamesFromUser, SAMSON::getSaveFileNameFromUser


function getDefaultDirectory#

Returns the default directory of the selector.

QString SBGWidgetFileSelector::getDefaultDirectory () const


function getFilePath#

Returns the path.

QString SBGWidgetFileSelector::getFilePath () 


function getFilter#

Returns the filter of the selector.

QString SBGWidgetFileSelector::getFilter () const


function getLabel#

Returns the label shown in the selector.

QString SBGWidgetFileSelector::getLabel () const


function setDefaultDirectory#

Sets the default directory for the selector that will be used for browse if the file path is not set.

void SBGWidgetFileSelector::setDefaultDirectory (
    const QString & dir
) 


function setFilePath#

Sets the path.

void SBGWidgetFileSelector::setFilePath (
    const QString & path
) 


function setFilter#

Sets the filter for the selector.

void SBGWidgetFileSelector::setFilter (
    const QString & filter
) 


function setLabel#

Sets the label shown in the selector.

void SBGWidgetFileSelector::setLabel (
    const QString & label
) 


function ~SBGWidgetFileSelector#

Destructs the path selector widget.

virtual SBGWidgetFileSelector::~SBGWidgetFileSelector () 


Public Static Functions Documentation#

function checkFile#

Check whether the file exists.

static bool SBGWidgetFileSelector::checkFile (
    const QString & path,
    bool askUser
)