PyQt5 QFileDialog Browsing Image

PyQt5 QFileDialog Browsing An Image

In this article iam going to talk about QFileDialog in PyQt5, especially we are going to
do Browsing in Image with QFileDialog in PyQt5 first o all The FileDialog widget provides a dialog useful for selecting of files. These are commonly used when a user wants to
open or save a file within the application.

 

So first we need to import some classes

After that we create our Window class that inherits from QWidget for creating Window article in PyQt5 check the  link. PyQt5 Creating Window
We have created two methods in this class the first one for setting our Window requirements and also we are going to create a QPushButton widget with a QVBoxLayout in that method. in the second method we create our QFileDialog.

 

Constructor 

Construction of the FileDialog widget is made using:

filedialog = QFileDialog()

To define whether the dialog is to be used for opening or saving files call:

filedialog.setAcceptMode(mode)

The mode value should be set to one of:

• QFileDialog.AcceptOpen
• QFileDialog.AcceptSave

Text can be displayed in the FileDialog indicating the purpose with:

filedialog.setLabelText(text)

A default suffix can be added for display if no other suffix is currently in use via:

filedialog.setDefaultSuffix(suffix)

The suffix parameter should be a string and is commonly used to identify the type of file such as ‘.txt’, ‘.odt’, or ‘.png’
Configuration of the displayed information within the FileDialog can be done with:

filedialog.setViewMode(mode)

The mode in this case can be set to:

• QFileDialog.Detail – display an icon, name, and details for each item.

• QFileDialog.List – display icon and name only.

In some cases, the requirement will be that the dialog only display certain file types. The Dir object can be set with:

filedialog.setFilter(filter)

 

 

At the end we create the object of our Window and QApplication

 

Complete source code for QFileDialog

 

Image for QFileDialog

PyQt5 QFileDialog Browsing Image
PyQt5 QFileDialog Example

 

 

 

(Visited 4,188 times, 12 visits today)
Share via
Copy link
Powered by Social Snap