Remove our custom stylesheeting, and just trim long names, allowing them to untrim as the window resizes

This commit is contained in:
Miguel Jacq 2018-02-23 10:49:43 +11:00
parent 1967d50707
commit ade9a452a3
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6

View File

@ -86,13 +86,6 @@ class FileList(QtWidgets.QListWidget):
self.drop_count = DropCountLabel(self) self.drop_count = DropCountLabel(self)
self.resizeEvent(None) self.resizeEvent(None)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.setStyleSheet(
"""
QListWidget::item { background-color: #ffffff; color: #000000; font-size: 13px; }
QListWidget::item:selected { background-color: #ddddff; }
QWidget#item-info { background-color: #fbfbfb; border: 1px solid #f0f0f0; border-radius: 5px; }
"""
)
def update(self): def update(self):
""" """
@ -141,6 +134,15 @@ class FileList(QtWidgets.QListWidget):
self.takeItem(self.row(item)) self.takeItem(self.row(item))
self.update() self.update()
# Extend any filenames that were truncated to fit the window
# We use 200 as a rough guess at how wide the 'file size + delete button' widget is
# and extend based on the overall width minus that amount.
for index in range(self.count()):
metrics = QtGui.QFontMetrics(self.item(index).font())
elided = metrics.elidedText(self.item(index).basename, QtCore.Qt.ElideRight, self.width() - 200)
self.item(index).setText(elided)
def dragEnterEvent(self, event): def dragEnterEvent(self, event):
""" """
dragEnterEvent for dragging files and directories into the widget. dragEnterEvent for dragging files and directories into the widget.
@ -208,7 +210,6 @@ class FileList(QtWidgets.QListWidget):
return return
fileinfo = QtCore.QFileInfo(filename) fileinfo = QtCore.QFileInfo(filename)
basename = os.path.basename(filename.rstrip('/'))
ip = QtWidgets.QFileIconProvider() ip = QtWidgets.QFileIconProvider()
icon = ip.icon(fileinfo) icon = ip.icon(fileinfo)
@ -229,8 +230,11 @@ class FileList(QtWidgets.QListWidget):
item_size = QtWidgets.QLabel(size_readable) item_size = QtWidgets.QLabel(size_readable)
item_size.setStyleSheet('QLabel { color: #666666; font-size: 11px; }') item_size.setStyleSheet('QLabel { color: #666666; font-size: 11px; }')
item.basename = os.path.basename(filename.rstrip('/'))
# Use the basename as the method with which to sort the list # Use the basename as the method with which to sort the list
item.setData(QtCore.Qt.DisplayRole, basename) metrics = QtGui.QFontMetrics(item.font())
elided = metrics.elidedText(item.basename, QtCore.Qt.ElideRight, self.sizeHint().width())
item.setData(QtCore.Qt.DisplayRole, elided)
# Item's delete button # Item's delete button
def delete_item(): def delete_item():