I am looking to create an image browser that shows nicely and evenly tiled thumbnails, on a native looking file browser.
On windows, I'm hoping it would look something similar to this:
On ubuntu, I'm hoping it would look something similar to this:
But this is what's available right now:
One of the issues I'm facing involves specifying the correct thumbnail size for the images. I understand that I can set the thumbnail size programatically by using the code self.setIconSize(QSize(32, 32))
, however, setting the thumbnail size this way may result in sizes inconsistent with the system default, making it look unnatural.
So my question is: How do I get the "default thumbnail size" that is set on the user's desktop, to make my thumbnail appearance consistent with the user's os (using qt5 or more specifically PySide2 or PyQt5)?
Here's the code I'm working with so far: `
import sys
from PySide2.QtCore import QSize
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import QApplication, QListWidget, QListWidgetItem, QMainWindow
class ThumbsWindow(QListWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.initUI()
def initUI(self):
self.setViewMode(QListWidget.IconMode)
self.setIconSize(QSize(32, 32))
myimage_path = "./images/web.png"
myimage_path1 = "./images/image1.jpg"
myimage_path2 = "./images/image2.jpg"
myimage_path3 = "./images/image3.jpg"
image_list = [myimage_path, myimage_path1, myimage_path2, myimage_path3]
# create a list of QIcons
image_items = [QListWidgetItem(QIcon(path_x), "sample image") for path_x in image_list]
# add each of the QIcons onto the QListWidget
for image_item in image_items:
self.addItem(image_item)
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
t = ThumbsWindow()
self.setCentralWidget(t)
self.resize(400, 300)
self.setWindowTitle('Image Thumbnails')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
`
I know I'm probably a little late to help by answering this, but I believe you are looking at this from the wrong approach.
As others have said there is not technically a "system default" size for image thumbnails. The thumbnails are displayed on a file manager program (Windows Explorer, Nautilus, etc.) which is what dictates the size of the thumbnails. Not the system.
Both of the programs above give the user the ability to adjust the size of the thumbnails, so even if there was a default system setting, one users preferred size would not be universal.
What you may want to do is open the default file manager beside your GUI and compare the icon sizes. If yours is smaller than the default file manager, adjust icon size in your code (the way you posted above) and compare again. When they look close enough to the same size to suite you, that's your default size. If you want to give the user the option to adjust the size, add the options in to adjust it and then save the new size as the icon size that is initialized when the application is started, allowing the user to choose their own default size.
Aside from this I don't believe there is a way to pull the icon size from the default file manager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With