Convert Uploads to a QScrollArea also

This commit is contained in:
Micah Lee 2018-09-29 13:47:00 -07:00
parent 05ec529d96
commit cbe882f2eb
2 changed files with 30 additions and 16 deletions

View File

@ -206,7 +206,7 @@ class Upload(QtWidgets.QWidget):
self.label.setText(text) self.label.setText(text)
class UploadList(QtWidgets.QListWidget): class UploadList(QtWidgets.QScrollArea):
""" """
List of upload progess bars. List of upload progess bars.
""" """
@ -216,9 +216,32 @@ class UploadList(QtWidgets.QListWidget):
self.uploads = {} self.uploads = {}
self.setMinimumHeight(205) # The layout that holds all of the uploads
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection) self.uploads_layout = QtWidgets.QVBoxLayout()
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.uploads_layout.setContentsMargins(0, 0, 0, 0)
self.uploads_layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
# Wrapper layout that also contains a stretch
wrapper_layout = QtWidgets.QVBoxLayout()
wrapper_layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
wrapper_layout.addLayout(self.uploads_layout)
wrapper_layout.addStretch()
# The internal widget of the scroll area
widget = QtWidgets.QWidget()
widget.setLayout(wrapper_layout)
self.setWidget(widget)
self.setWidgetResizable(True)
# Other scroll area settings
self.setBackgroundRole(QtGui.QPalette.Light)
self.verticalScrollBar().rangeChanged.connect(self.resizeScroll)
def resizeScroll(self, minimum, maximum):
"""
Scroll to the bottom of the window when the range changes.
"""
self.verticalScrollBar().setValue(maximum)
def add(self, upload_id, content_length): def add(self, upload_id, content_length):
""" """
@ -226,10 +249,7 @@ class UploadList(QtWidgets.QListWidget):
""" """
upload = Upload(self.common, upload_id, content_length) upload = Upload(self.common, upload_id, content_length)
self.uploads[upload_id] = upload self.uploads[upload_id] = upload
self.uploads_layout.addWidget(upload)
item = QtWidgets.QListWidgetItem()
self.addItem(item)
self.setItemWidget(item, upload)
def update(self, upload_id, progress): def update(self, upload_id, progress):
""" """
@ -260,14 +280,8 @@ class UploadList(QtWidgets.QListWidget):
""" """
Reset the uploads back to zero Reset the uploads back to zero
""" """
# Remove all items from list
while True:
item = self.takeItem(0)
if not item:
break
# Close all progress bars
for upload in self.uploads.values(): for upload in self.uploads.values():
self.uploads_layout.removeWidget(upload)
upload.progress_bar.close() upload.progress_bar.close()
self.uploads = {} self.uploads = {}

View File

@ -148,7 +148,7 @@ class DownloadList(QtWidgets.QScrollArea):
Reset the downloads back to zero Reset the downloads back to zero
""" """
for download in self.downloads.values(): for download in self.downloads.values():
self.downloads_layout.removeWidget(download.progress_bar) self.downloads_layout.removeWidget(download)
download.progress_bar.close() download.progress_bar.close()
self.downloads = {} self.downloads = {}