I'm creating a file browser with PyQt6. This is what I'm thinking of doing right now:
from PyQt6 import QtWidgets as qtw
from PyQt6 import QtGui as qtg
class FileBrowserWidget(qtw.QScrollArea):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.current_items = []
self.main_widget = qtw.QWidget()
self.main_widget.setLayout(qtw.QVBoxLayout())
self.setWidget(self.main_widget)
def add_file(self, thumbnail: qtg.QPixmap, description: str):
item = qtw.QWidget()
item.setLayout(qtw.QHBoxLayout())
file_thumbnail_label = qtw.QLabel()
file_thumbnail_label.setPixmap(thumbnail)
file_description_label = qtw.QLabel(description)
item.layout().addWidget(file_thumbnail_label)
item.layout().addWidget(file_description_label)
self.current_items.append(item)
Note that this is just a rough sketch of the widget. All the code does is display a (thumbnail, description)
pair for files inside a directory in a scrollable window. I also plan to implement pagination for it, with at least 25 rows (files) per page.
My questions are:
- Is this the way to do it or is there some other better way to go about creating a file browser?
- How would I go about implementing pagination to the file browser?
EDIT: