Convert Uploads to a QScrollArea also

This commit is contained in:
Micah Lee 2018-09-29 13:47:00 -07:00
parent d87115d21e
commit fa4ebbf263
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 30 additions and 16 deletions

View File

@ -206,7 +206,7 @@ class Upload(QtWidgets.QWidget):
self.label.setText(text)
class UploadList(QtWidgets.QListWidget):
class UploadList(QtWidgets.QScrollArea):
"""
List of upload progess bars.
"""
@ -216,9 +216,32 @@ class UploadList(QtWidgets.QListWidget):
self.uploads = {}
self.setMinimumHeight(205)
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
# The layout that holds all of the uploads
self.uploads_layout = QtWidgets.QVBoxLayout()
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):
"""
@ -226,10 +249,7 @@ class UploadList(QtWidgets.QListWidget):
"""
upload = Upload(self.common, upload_id, content_length)
self.uploads[upload_id] = upload
item = QtWidgets.QListWidgetItem()
self.addItem(item)
self.setItemWidget(item, upload)
self.uploads_layout.addWidget(upload)
def update(self, upload_id, progress):
"""
@ -260,14 +280,8 @@ class UploadList(QtWidgets.QListWidget):
"""
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():
self.uploads_layout.removeWidget(upload)
upload.progress_bar.close()
self.uploads = {}

View File

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